目录
一、关于本文
本文可以快速在Spring boot项目中集成Mybatis,完成相关配置和类代码。
二、需要加入的配置和类
- application.yml
- pom.xml
- mybatis-config.xml
- pojo类
- mapper接口
- mapper.xml
- 测试类
三、加入配置和类
3.1 application.yml
#配置数据库信息
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://10.4.227.237:3306/ccpaccount_qa
username: test-001
password: test-001
type: org.apache.commons.dbcp.BasicDataSource
#配置mybatis mapper.xml
mybatis:
config-location:
classpath: mybatis-config.xml
mapper-locations:
classpath: mapper/*Mapper.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#mybatis-pagehelper分页插件
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
3.2 pom.xml
<!-- springboot和mybatis集成中间件 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.spring.boot.version}</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
</dependency>
<!-- 数据库连接池 -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons.d