一、配置pom.xml
<!-- springboot整合MyBatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- alibaba的druid数据库连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.11</version> </dependency> <!-- 分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.1.2</version> </dependency>
二、配置application.yml
spring: datasource: name: sp url: jdbc:mysql://192.168.2.120:3306/sp?characterEncoding=utf8&useSSL=false username: root password: 123456 type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20 mybatis: mapper-locations: classpath:mapper/* #type-aliases-package: com.wuxi.beans config-location: classpath:mybatis/mybatis-config.xml pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql
三、配置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> </configuration>
四、配置MyApplication.class
@SpringBootApplication(scanBasePackages = {"com.wuxi"}) @MapperScan("com.wuxi.dao") public class MyApplication { //入口 public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
五、事务管理
@Transactional
六、分页插件使用在整合测试章节