|
|
@@ -1,36 +1,23 @@ |
|
|
|
package com.tuoheng.config; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.DbType; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
|
|
|
|
|
|
@Configuration |
|
|
|
@EnableTransactionManagement(proxyTargetClass = true) |
|
|
|
public class MybatisPlusConfig { |
|
|
|
|
|
|
|
/** |
|
|
|
* 插件注册 |
|
|
|
* 分页插件 |
|
|
|
* |
|
|
|
* @param paginationInnerInterceptor 分页插件 |
|
|
|
* @return MybatisPlus拦截器 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Bean |
|
|
|
public MybatisPlusInterceptor mybatisPlusInterceptor(PaginationInnerInterceptor paginationInnerInterceptor) { |
|
|
|
MybatisPlusInterceptor mp = new MybatisPlusInterceptor(); |
|
|
|
mp.addInnerInterceptor(paginationInnerInterceptor); |
|
|
|
return mp; |
|
|
|
public PaginationInterceptor paginationInterceptor() { |
|
|
|
PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); |
|
|
|
paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true)); |
|
|
|
return paginationInterceptor; |
|
|
|
} |
|
|
|
|
|
|
|
//分页插件 |
|
|
|
@Bean |
|
|
|
public PaginationInnerInterceptor paginationInnerInterceptor() { |
|
|
|
PaginationInnerInterceptor pii = new PaginationInnerInterceptor(); |
|
|
|
pii.setMaxLimit(20L); |
|
|
|
pii.setDbType(DbType.MYSQL); |
|
|
|
//当超过最大页数时不会报错 |
|
|
|
pii.setOverflow(true); |
|
|
|
return pii; |
|
|
|
} |
|
|
|
|
|
|
|
} |