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>
    

      

  • 相关阅读:
    python之各种包
    正则表达式
    import/模块的导入
    迭代器/可迭代对象/生成器
    Day2 列表list
    Day1 字符串格式化
    Day1 字符编码及编码函数
    Python 学习笔记 之 随着学习不断更新的Python特性搜集
    Day1 input&print
    Newtonsoft.Json日期转换
  • 原文地址:https://www.cnblogs.com/SkyeAngel/p/8421355.html
Copyright © 2011-2022 走看看