• 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>  
  • 相关阅读:
    解决electron-vue中无法使用Element的Tooltip组件
    解决Electron安装包下载慢的问题
    虚拟机VirtualBox 共享挂载问题:mount: /mnt/xxx: wrong fs type, bad option, bad superblock on xxx
    git 设置和取消代理
    (转载)数据库连接池到底应该设多大?这篇文章可能会颠覆你的认知
    MySQL主主复制+MMM实现高可用
    Mysql5.6主从热备配置
    java 启动 shell脚本
    redis批量删除key
    spring mvc异常统一处理(ControllerAdvice注解)
  • 原文地址:https://www.cnblogs.com/liufei1983/p/7476323.html
Copyright © 2020-2023  润新知