mybatis xml配置文件模版

mybatis xml配置文件模版

 

1、mybatis核心配置文件书写(SqlMapConfig.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>
<environments default=”development”>
<environment id=”development”>
<!–使用jdbc事务管理 –>
<transactionManager type=”JDBC”/>
<!– 数据库连接池 –>
<dataSource type=”POOLED”>
<property name=”driver” value=”com.mysql.jdbc.Driver”/>
<property name=”url” value=”jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8″/>
<property name=”username” value=”root”/>
<property name=”password” value=”1234″/>
</dataSource>
</environment>
</environments>
<!– 引入映射配置文件 –>
<mappers>
<mapper resource=”cn/zhku/jsj/mybatis/pojo/User.xml”/>
</mappers>
</configuration>

2、mybatis映射配置文件书写(User.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”>

<!– namespace:命名空间,用于隔离sql–>
<mapper namespace=”user”>
<select id=”findUserByUsername” parameterType=”String” resultType=”cn.zhku.jsj.mybatis.pojo.User”>
select * from user where username like ‘%${value}%’
</select>
</mapper>

 

    原文作者:MyBatis
    原文地址: https://www.cnblogs.com/wenhuang/p/9803272.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞