Guwan-smartSchool/shapelight-admin/src/main/java/net/shapelight/common/config/MybatisPlusConfig.java

86 lines
3.2 KiB
Java
Raw Normal View History

2020-10-19 17:44:19 +08:00
package net.shapelight.common.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* mybatis-plus配置
*
*
*/
@Configuration
public class MybatisPlusConfig {
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
// @Bean
// public ISqlInjector sqlInjector() {
// return new LogicSqlInjector();
// }
// @Bean
// public PaginationInterceptor paginationInterceptor() {
// PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// DynamicTableNameParser dynamicTableNameParser = new DynamicTableNameParser();
// // 创建SQL解析器集合
// List<ISqlParser> sqlParserList = new ArrayList<>();
//
// Map<String,ITableNameHandler> tableNameHandlerMap = new HashMap<>();
// // Map的key就是需要替换的原始表名
// tableNameHandlerMap.put("ten_cell",new ITableNameHandler(){
// @Override
// public String dynamicTableName(MetaObject metaObject, String sql, String tableName) {
// // 自定义表名规则或者从配置文件、request上下文中读取
//
// // 假设这里的用户表根据年份来进行分表操作
// Date date = new Date();
// String year = String.format("%tY", date);
// // 返回最后需要操作的表名sys_user_2019
// return "ten_cell_" + year;
// }
// });
//
// tableNameHandlerMap.put("ten_cell",new ITableNameHandler(){
// @Override
// public String dynamicTableName(MetaObject metaObject, String sql, String tableName) {
// // 自定义表名规则或者从配置文件、request上下文中读取
//
// // 假设这里的用户表根据年份来进行分表操作
// Date date = new Date();
// String year = String.format("%tY", date);
// // 返回最后需要操作的表名sys_user_2019
// return "ten_cell_" + 2019;
// }
// });
//
//
// dynamicTableNameParser.setTableNameHandlerMap(tableNameHandlerMap);
// sqlParserList.add(dynamicTableNameParser);
// paginationInterceptor.setSqlParserList(sqlParserList);
//
//// dynamicTableNameParser.setTableNameHandlerMap(new HashMap<String, ITableNameHandler>(2) {{
//// put("sysUserEntity", (metaObject, sql, tableName) -> {
//// // metaObject 可以获取传入参数,这里实现你自己的动态规则
//// String year = "_2018";
//// int random = new Random().nextInt(10);
//// if (random % 2 == 1) {
//// year = "_2019";
//// }
//// return tableName + year;
//// return tableName + (String)metaObject.getValue("schema");
//// });
//// }});
//// paginationInterceptor.setSqlParserList(Collections.singletonList(dynamicTableNameParser));
// return paginationInterceptor;
// }
}