Mybatis Plus多租户

烈酒焚心 提交于 2020-10-28 10:29:39
/**
 * 分页
 * @return
 */
@Bean
public PaginationInterceptor paginationInterceptor(){
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();

    ArrayList<ISqlParser> sqlParserList = new ArrayList<ISqlParser>();
    TenantSqlParser tenantSqlParser = new TenantSqlParser();
    tenantSqlParser.setTenantHandler(new TenantHandler() {
        @Override
        public Expression getTenantId(boolean where) {
            return new LongValue(79657654768L);
        }

        @Override
        public String getTenantIdColumn() {
            return "parent_id";
        }

        @Override
        public boolean doTableFilter(String tableName) {
            //表示role表不是多租户
            if("role".equals(tableName)){
                return true;
            }
            return false;
        }
    });
    sqlParserList.add(tenantSqlParser);
    paginationInterceptor.setSqlParserList(sqlParserList);

    //特定方法不使用多租户
    paginationInterceptor.setSqlParserFilter(new ISqlParserFilter() {
        @Override
        public boolean doFilter(MetaObject metaObject) {
            MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject);
            if("com.xiao.permission_system.UserInfoMapper.selectById".equals(ms.getId())){
                return true;
            }



            return false;
        }
    });

    return  new PaginationInterceptor();
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!