电子商务网站建设需求概述成都网站建设138
news/
2025/10/1 7:53:38/
文章来源:
电子商务网站建设需求概述,成都网站建设138,怎么建设一个漫画网站,网站做半透明度的优势背景#xff1a;项目使用mybatis分页插件不生效#xff0c;以及多租户使用时读取配置异常
分页插件不细述#xff0c;网上很多方法试了还是不生效#xff0c;最后修改到当前版本解决#xff0c;直接上代码
多租户插件使用遇到的问题#xff1a;
最开始在MyTenantLineH…背景项目使用mybatis分页插件不生效以及多租户使用时读取配置异常
分页插件不细述网上很多方法试了还是不生效最后修改到当前版本解决直接上代码
多租户插件使用遇到的问题
最开始在MyTenantLineHandler中使用 Value(${tables}),服务启动时能从配置中心拉取到配置但在运行时获取到的值为空试了很多方法都不生效后面将配置中心的配置在调用MyTenantLineHandler的那一层向下传递配置值问题解决 租户配置
Component
RefreshScope
ConfigurationProperties(prefix saas.tenant)
public class ConfigProperties {public void setColumn(String column) {this.column column;}public void setTables(ListString tables) {this.tables tables;}public String getColumn(){return this.column;}public ListString getTables(){return this.tables;}private String column;private ListString tables Lists.newArrayList();
}
TenantLineHandler
public class MyTenantLineHandler implements TenantLineHandler {private final ConfigProperties configProperties;public MyTenantLineHandler(ConfigProperties configProperties) {this.configProperties configProperties;}Overridepublic LongValue getTenantId() {Long tenantId TenantContextHolder.getTenantId();return tenantId null ? new LongValue(-1) : new LongValue(tenantId);}Overridepublic String getTenantIdColumn() {return configProperties.getColumn();}Overridepublic boolean ignoreTable(String tableName) {return !configProperties.getTables().contains(tableName);// return TenantLineHandler.super.ignoreTable(tableName);}
}
MybatisPlusConfig
Configuration
AutoConfigureAfter(PageHelperAutoConfiguration.class)
//EnableTransactionManagement
public class MybatisPlusConfig {Autowiredprivate ListSqlSessionFactory sqlSessionFactoryList;Autowiredprivate ConfigProperties configProperties;PostConstructpublic void addMyInterceptor() {MybatisPlusInterceptor interceptor mybatisPlusInterceptor();for (SqlSessionFactory factory : sqlSessionFactoryList) {factory.getConfiguration().addInterceptor(interceptor);}}/*** mybatisplus 分页拦截器* return*/public MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor());TenantLineInnerInterceptor tenantLineInnerInterceptornew TenantLineInnerInterceptor();tenantLineInnerInterceptor.setTenantLineHandler(new MyTenantLineHandler(configProperties));interceptor.addInnerInterceptor(tenantLineInnerInterceptor);return interceptor;}
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/923626.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!