zoukankan      html  css  js  c++  java
  • JavaEE——Mybatis(12)--MyBatis与Spring整合--MyBatis相关配置文件

     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>
    
        <!--引入外部properties配置文件-->
        <properties resource="confdbconfig.properties"></properties>
    
        <environments default="development">
            <environment id="development">
                <transactionManager type="JDBC"/>
                <dataSource type="POOLED">
                    <property name="driver" value="${driver}"/>
                    <property name="url" value="${url}"/>
                    <property name="username" value="${username}"/>
                    <property name="password" value="${password}"/>
                </dataSource>
            </environment>
        </environments>
        <mappers>
            <mapper resource="studentMapper.xml"/>
        </mappers>
    </configuration>
    

      

    dbconfig.properties

    driver=com.mysql.jdbc.Driver
    url=jdbc:mysql://localhost:3306/db_person
    username=root
    password=1234
    

      

    相应的StudentMapper接口

    package dao;
    
    import bean.Student;
    
    public interface StudentMapper {
    
        public Student getById(Integer id);
    }
    

      

    以及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="test.dao.StudentMapper">
    
        <!--public Student getById(Integer id);-->
        <select id="getById" resultType="bean.Student">
            SELECT * FROM student WHERE id=#{id}
        </select>
    </mapper>
    

      

  • 相关阅读:
    贪心法之最优装载问题
    判断回文
    P1217 [USACO1.5]回文质数 Prime Palindromes
    李白打酒
    P1036 选数
    P1028 数的计算
    P1316 丢瓶盖
    P1181 数列分段Section I
    P1182 数列分段`Section II`
    P1216 [IOI1994][USACO1.5]数字三角形 Number Triangles
  • 原文地址:https://www.cnblogs.com/SkyeAngel/p/8421355.html
Copyright © 2011-2022 走看看