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>
    

      

  • 相关阅读:
    jQuery琐碎
    jQuery文档加载事件
    微信,禁止分享页面
    级联下拉列表
    struts2 result随笔
    C++知识点(四)类与对象,结构体、联合体、枚举类
    C++知识点(三)函数
    剑指offer-二叉树
    LeetCode:Remove Element
    LeetCode:Remove Duplicates from Sorted Array
  • 原文地址:https://www.cnblogs.com/SkyeAngel/p/8421355.html
Copyright © 2011-2022 走看看