一、添加依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
二、spring boot 配置
server.port=8797
#等待队列长度,默认为100
server.tomcat.accept-count=100
#最大可被连接数
server.tomcat.max-connections=10000
#最大线程数
server.tomcat.max-threads=200
#最小线程数
server.tomcat.min-spare-threads=10 spring.application.name=service server.servlet.context-path=/service spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root spring.datasource.hikari.connection-test-query=select 1
spring.datasource.hikari.read-only=false
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.idle-timeout=600000
spring.datasource.hikari.max-lifetime=60000
spring.datasource.hikari.maximum-pool-size=10 mybatis-plus.mapper-locations=classpath*:/mapper/**/*.xml
mybatis-plus.type-aliases-package=com.mz.mzservice.*.entity
mybatis-plus.type-aliases-super-type=com.mz.mzservice.entity.BaseEntity
mybatis-plus.global-config.banner=false
三、mybatis plus 配置,包含分页
添加一个 配置类
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableTransactionManagement
@Configuration
@MapperScan("com.mz.mzservice.*.mapper")
public class MybatisPlusConfig { @Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
// paginationInterceptor.setOverflow(false);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
// paginationInterceptor.setLimit(500);
return paginationInterceptor;
}
}
搞定,可以愉快的使用了。
配合我的另一篇代码生成的文章 https://www.cnblogs.com/enenen/p/11704351.html 可以更快的上手使用。