• mybatis 学习三 关键文件解析


    1:  mybatis-config.xml

    <?xml version="1.0" encoding="UTF-8" ?>  
    <!DOCTYPE configuration  
      PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  
      "http://mybatis.org/dtd/mybatis-3-config.dtd">     
    <configuration>  
        <!-- 全局别名设置,在映射文件中只需写别名,而不必写出整个类路径  -->  
        <typeAliases>    
             <typeAlias type="com.deppon.test04.entity.StudentEntity" alias="StudentEntity"/>   
        </typeAliases>   
        <mappers>  
            <mapper resource="StudentMapper.xml" />    <!--  可以定义多个mapper>
        </mappers>  
    </configuration>  

    2: StudentMapper.xml

    <?xml version="1.0" encoding="UTF-8" ?>  
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
    <mapper namespace="com.deppon.test04.dao.StudentMapper">  
        <resultMap type="StudentEntity" id="studentResultMap">  
            <id property="studentID" column="STUDENT_ID"/>  
            <result property="studentName" column="STUDENT_NAME"/>  
            <result property="studentSex" column="STUDENT_SEX"/>  
            <result property="studentBirthday" column="STUDENT_BIRTHDAY"/>  
        </resultMap>  
        <!-- 查询学生,根据id -->  
        <select id="getStudent" parameterType="String" resultType="com.deppon.test04.entity.StudentEntity" resultMap="studentResultMap">  
            <![CDATA[ 
                SELECT * from STUDENT_TBL ST 
                    WHERE ST.STUDENT_ID = #{studentID}  
            ]]>   
        </select>  
        <!-- 查询学生列表 -->  
        <select id="getStudentAll"  resultType="com.deppon.test04.entity.StudentEntity" resultMap="studentResultMap">  
            <![CDATA[ 
                SELECT * from STUDENT_TBL 
            ]]>   
        </select>   
    </mapper>  

    3:  mysql.properties

    jdbc.driverClassName=com.mysql.jdbc.Driver  
    jdbc.url=jdbc:mysql://localhost:3306/student_manager?user=root&password=root&useUnicode=true&characterEncoding=UTF-8

    4: dispatcherServlet

     <mvc:annotation-driven />  
        <context:component-scan base-package="liming.maven.example" /> 
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
            <property name="prefix" value="/WEB-INF/" />  
            <property name="suffix" value=".jsp" />  
        </bean>  
        <!-- 导入属性配置文件 -->  
        <context:property-placeholder location="classpath:mysql.properties" />  
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
                <property name="driverClassName" value="${jdbc.driverClassName}" />  
                <property name="url" value="${jdbc.url}" />  
        </bean>  
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
        <property name="dataSource" ref="dataSource" />  
    </bean>  
      
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="configLocation" value="classpath:mybatis-config.xml" />  
        <property name="dataSource" ref="dataSource" />  
    </bean>  
    <bean id="studentMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">  
        <property name="mapperInterface" value="com.deppon.test04.dao.StudentMapper" />  
        <property name="sqlSessionFactory" ref="sqlSessionFactory" />  
    </bean>  
  • 相关阅读:
    打印杨辉三角 --JS
    (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数&lt;=3,输出剩下的人 )
    黑马day16 jquery&amp;属性过滤选择器
    JQuery学习(4-2-phpserver端1)
    微信企业号开发:启用回调模式
    Struts框架的国际化
    4、libgdx应用框架
    C++map类型 之 简单介绍
    图像处理与计算机视觉开源软件库及学习站点
    单例模式
  • 原文地址:https://www.cnblogs.com/liufei1983/p/7476323.html
Copyright © 2020-2023  润新知