Mybatis学习笔记

2021/11/26 Mybatis

官方资料:

https://mybatis.org/mybatis-3/index.html (opens new window)

https://mybatis.org/mybatis-3/zh/index.html (opens new window)

http://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/ (opens new window)

约束文件:

http://mybatis.org/dtd/mybatis-3-config.dtd (opens new window)

http://mybatis.org/dtd/mybatis-3-mapper.dtd (opens new window)

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>
  <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="org/mybatis/example/BlogMapper.xml"/>
  </mappers>
</configuration>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

*Mapper.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="">
</mapper>
1
2
3
4
5
6