heykb / mybatis-sqlhelper

MyBatis sql注入、多租户、逻辑删除、数据权限插件-SqlHelper
MIT License
58 stars 23 forks source link

若依前后分离版集成该插件不生效 #4

Closed zh-new closed 2 years ago

zh-new commented 2 years ago

按照SpirngBoot版本的配置步骤,集成到若依前后分离版中,实现多租户功能,插件不生效,不知道是不是与分页插件冲突?

heykb commented 2 years ago

@zh-new 哪个版本

zh-new commented 2 years ago

RuoYi-Vue 集成 mybatis-sqlhelper-spring-boot-starter:3.0.0.SR1

heykb commented 2 years ago

@zh-new 原理上sqlhelper并不会与其他插件冲突,使用3.0.0.SR1版本,然后检查以下配置(默认情况下它们为true),检查bean是否正常注入sqlhelper.enable=true sqlhelper.multi-tenant.enable=true

heykb commented 2 years ago

@zh-new 可尝试io.github.heykb.sqlhelper.interceptor.SqlHelperPlugin的intercept方法下打入断点,检查代码执行是否进入插件了

zh-new commented 2 years ago

debug结果:setProperties能进入,intercept是没有进入,意思是没有拦截不到,两个query都拦截,我早上自己写拦截接口,能正常拦截

heykb commented 2 years ago

@zh-new ruoyi的版本是哪个

zh-new commented 2 years ago
3.8.2
heykb commented 2 years ago

@zh-new 修改com.ruoyi.framework.config.MyBatisConfig文件,

@Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ObjectProvider<Interceptor[]> interceptorsProvider) throws Exception
    {
        String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
        String mapperLocations = env.getProperty("mybatis.mapperLocations");
        String configLocation = env.getProperty("mybatis.configLocation");
        typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
        VFS.addImplClass(SpringBootVFS.class);
        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
      // 注入插件
        sessionFactory.setPlugins(interceptorsProvider.getIfAvailable());
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
        sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));

        return sessionFactory.getObject();
    }
zh-new commented 2 years ago

@heykb 能生效