【mybatis】学习笔记之conf.xml与mapper.xml配置

在学习mybatis时,发现对配置文件的要求严格,这里进行笔记:

1.mapper.xml与conf.xml文件需要文件头,可以在mybatis的文档里查找到

2.配置mapper.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE mapper  
 3 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 <mapper namespace="pers.yjc.work.mapper.personMapper">
 6 <!-- 没有分号 -->
 7     <!-- 查询单个person -->
 8     <select id="queryPersonById" resultType="pers.yjc.work.entity.Person" parameterType="int"> 
 9         select * from person where id = #{id}
10     </select>
11 </mapper>
namespace="pers.yjc.work.mapper.personMapper"这里写mapper.xml的路径,注意是用“.”来分割,末尾不加“.xml”

3.配置conf.xml

 1 <?xml version="1.0" encoding="UTF-8" ?> 
 2 <!DOCTYPE configuration  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 3 "http://mybatis.org/dtd/mybatis-3-config.dtd">
 4 <configuration>
 5     <environments default="development">
 6         <environment id="development">
 7             <transactionManager type="JDBC" />
 8             <dataSource type="POOLED">
 9                 <property name="driver" value="com.mysql.cj.jdbc.Driver" />
10                 <property name="url" value="jdbc:mysql://localhost:3306/test?serverTimezone=UTC&amp;useSSL=false" />
11                 <property name="username" value="root" />
12                 <property name="password" value="root123" />
13             </dataSource>
14         </environment>
15     </environments>
16     <mappers>
17         <mapper resource="pers/yjc/work/mapper/personMapper.xml" />
18     </mappers>
19 </configuration>
<mappers>
    <mapper resource="pers/yjc/work/mapper/personMapper.xml" />
</mappers>
这里也写mapper.xml的路径,不过这里就要用“/”分隔,还要加上后缀
 

【mybatis】学习笔记之conf.xml与mapper.xml配置

上一篇:使用JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超过了为 maxJsonLength属性


下一篇:java web开发中,如何查看JSP和Servlet版本 (转)