|
@@ -1,5 +1,7 @@
|
|
package com.persagy.dmp.mybatis.config;
|
|
package com.persagy.dmp.mybatis.config;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
|
+import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
|
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
|
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
|
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
@@ -30,6 +32,8 @@ public class MybatisPlusConfig implements CommandLineRunner {
|
|
private ObjectMapper objectMapper;
|
|
private ObjectMapper objectMapper;
|
|
@Value("${persagy.common.sql.limit:500}")
|
|
@Value("${persagy.common.sql.limit:500}")
|
|
private long sqlLimit;
|
|
private long sqlLimit;
|
|
|
|
+ @Value("${persagy.common.sql.db.type:mysql}")
|
|
|
|
+ private String dbType;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void run(String... args) throws Exception {
|
|
public void run(String... args) throws Exception {
|
|
@@ -37,36 +41,28 @@ public class MybatisPlusConfig implements CommandLineRunner {
|
|
JacksonTypeHandler.setObjectMapper(objectMapper);
|
|
JacksonTypeHandler.setObjectMapper(objectMapper);
|
|
}
|
|
}
|
|
|
|
|
|
- @Bean
|
|
|
|
- public PaginationInterceptor paginationInterceptor() {
|
|
|
|
- PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
|
|
|
|
- // 设置每页查询记录上限,默认500(与mp相同)
|
|
|
|
- paginationInterceptor.setLimit(sqlLimit);
|
|
|
|
- return paginationInterceptor;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
- * 注册Mybatis分页插件
|
|
|
|
|
|
+ * 注册Mybatis插件
|
|
* 使用示例: IPage<Member> memberPage = new Page<>(1, 2,false) true查询总记录数量
|
|
* 使用示例: IPage<Member> memberPage = new Page<>(1, 2,false) true查询总记录数量
|
|
*/
|
|
*/
|
|
-// @Bean
|
|
|
|
-// public PaginationInnerInterceptor paginationInnerInterceptor() {
|
|
|
|
-// PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
|
|
|
|
-// // 设置每页查询记录上限,默认500(与mp相同)
|
|
|
|
-// paginationInnerInterceptor.setMaxLimit(sqlLimit);
|
|
|
|
-// return paginationInnerInterceptor;
|
|
|
|
-// }
|
|
|
|
|
|
+ @Bean
|
|
|
|
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
|
|
|
+ MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
|
|
|
|
+ PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
|
|
|
|
+ // 设置每页查询记录上限,默认500(与mp相同)
|
|
|
|
+ paginationInnerInterceptor.setMaxLimit(sqlLimit);
|
|
|
|
+ paginationInnerInterceptor.setDbType(DbType.getDbType(dbType));
|
|
|
|
+ // 添加分页插件
|
|
|
|
+ mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
|
|
|
|
+ return mybatisPlusInterceptor;
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
- * 注册Mybatis插件
|
|
|
|
- * 使用示例: IPage<Member> memberPage = new Page<>(1, 2,false) true查询总记录数量
|
|
|
|
|
|
+ * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
|
|
*/
|
|
*/
|
|
-// @Bean
|
|
|
|
-// public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
|
|
|
-// MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
|
|
|
|
-// // 添加分页插件
|
|
|
|
-// mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor());
|
|
|
|
-// return mybatisPlusInterceptor;
|
|
|
|
-// }
|
|
|
|
|
|
+ @Bean
|
|
|
|
+ public ConfigurationCustomizer configurationCustomizer() {
|
|
|
|
+ return configuration -> configuration.setUseDeprecatedExecutor(false);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 自动扫描typeHandlers
|
|
* 自动扫描typeHandlers
|