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>
    

      

  • 相关阅读:
    mysql联合索引命中条件
    Shiro知识初探(更新中)
    Java中使用MongoTemplate进行分批处理数据
    Java中String时间范围比较
    使用ReentrantLock
    使用Condition
    python的坑--你知道吗?
    python基础--函数全解析(1)
    CSS基本语法及页面引用
    HTML学习汇总
  • 原文地址:https://www.cnblogs.com/SkyeAngel/p/8421355.html
Copyright © 2011-2022 走看看