若依(RuoYi)整合mybatis-plus,亲测有效

时间:2025-03-10 07:13:12

最近项目用的是ruoyi框架,但是若依用的是mybatis,有些时候用mybatis-plus比较好用,这个时候就需要引入mybtis-plus

首先在项目目录下的pom文件中加入依赖

    <properties>
        <>3.5.1</>
    </properties>
    <!-- 依赖声明 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId></groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

之后我们要在common模块的pom文件中加入依赖

<dependencies>
        <!--   mybatis-plus     -->
        <dependency>
            <groupId></groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>
</dependencies>

然后修改framework模块config文件下的mybatisconfig类

 @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
    {
        String typeAliasesPackage = ("");
        String mapperLocations = ("");
        String configLocation = ("");
        typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
        ();

        final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
        (dataSource);
        (typeAliasesPackage);
        (resolveMapperLocations((mapperLocations, ",")));
        (new DefaultResourceLoader().getResource(configLocation));
        return ();
    }

最后修改admin模块中的

mybatis-plus:
  # 对应的 XML 文件位置
  mapperLocations: classpath*:mapper/**/*
  # 实体扫描,多个package用逗号或者分号分隔
  typeAliasesPackage: .**.domain
  # 加载全局的配置文件
  configLocation: classpath:mybatis/

  type-aliases-package: .**.domain
  mapper-locations: classpath*:mapper/**/*
  configuration:
    cache-enabled: true
    use-generated-keys: true
    default-executor-type: simple
    log-impl: .slf4j.Slf4jImpl