Mybatis Plus動態表

/**
 * 動態表
 * @return
 */
@Bean
public PaginationInterceptor paginationInterceptor2(){
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();

    ArrayList<ISqlParser> sqlParserList = new ArrayList<ISqlParser>();

    DynamicTableNameParser dynamicTableNameParser = new DynamicTableNameParser();
    Map<String, ITableNameHandler> tableNameHandlerMap = new HashMap<>();
    tableNameHandlerMap.put("user", new ITableNameHandler() {
        @Override
        public String dynamicTableName(MetaObject metaObject, String sql, String tableName) {
            return myTableName.get();
        }
    });
    dynamicTableNameParser.setTableNameHandlerMap(tableNameHandlerMap);
    sqlParserList.add(dynamicTableNameParser);
    return  paginationInterceptor;
}



/**
 * 查詢動態表數據
 */
@Test
public void selectById2() {
    MybatisPlusConfig.myTableName.set("user_2019");
    List<UserInfo> userInfoSectList= user.selectList();
    userInfoSectList.forEach(System.out::println);
}
相關文章
相關標籤/搜索