当前位置:首页 >休闲 >若依开源使用MybatisPlus 这就增加了我们的使用工作量

若依开源使用MybatisPlus 这就增加了我们的使用工作量

2024-07-01 09:16:40 [百科] 来源:避面尹邢网

若依开源使用MybatisPlus

作者:学不会编程 开源 若依默认使用的若依是Mybatis和PageHelprt,在开发时,开源时有字段更改、使用新增的若依情况,这时需要我们去更新Mapper.xml中的开源SQL和字段映射,这就增加了我们的使用工作量。由此,若依我们便调整为Mybatis 开源Plus来提升我们的效率。

若依是使用目前比较火的开源后台管理系统,有完善的若依权限体系和后台管理功能。基于该系统开发业务系统,开源可以省去我们很多关于基础配置的使用开发,让我们更加专注于业务开发,若依而且框架也提供了基础的开源前后端代码生成功能,可是使用,若依默认使用的是Mybatis和PageHelprt,在开发时,时有字段更改、新增的情况,这时需要我们去更新Mapper.xml中的SQL和字段映射,这就增加了我们的工作量。由此,我们便调整为Mybatis Plus来提升我们的效率。

若依开源使用MybatisPlus 这就增加了我们的使用工作量

1、删掉Mybatis依赖

去父级pom.xml删除Mybatis依赖。

若依开源使用MybatisPlus 这就增加了我们的使用工作量

<!--            <dependency>-->
<!-- <groupId>org.mybatis.spring.boot</groupId>-->
<!-- <artifactId>mybatis-spring-boot-starter</artifactId>-->
<!-- <version>${ mybatis-spring-boot.version}</version>-->
<!-- </dependency>-->

我们来看看pagehelper-spring-boot-starter中依赖的Mybatis版本

若依开源使用MybatisPlus 这就增加了我们的使用工作量

这里我用的是mybatis-plus 3.5.2版,其中依赖的Mybatis版本会和PageHelper中Mybatis版本冲突,所以需要将PageHelper中的Mybatis的依赖排除掉。

<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${ pagehelper.boot.version}</version>
<exclusions>
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
</exclusions>
</dependency>

接下来注释掉MyBatisConfig中的@Configuration。

//@Configuration
public class MyBatisConfig

当然,你也可以选择注释掉整个类。

2、添加Mybatis Plus的依赖

去父级pom.xml添加。

<mybatis-plus-spring-boot.version>3.5.2</mybatis-plus-spring-boot.version>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${ mybatis-plus-spring-boot.version}</version>
</dependency>

然后去common模块中的pom.xml中添加依赖。

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>

3、配置Mybatis Plus信息

先去admin模块的application.yml中注释掉原来的Mybatis配置

## MyBatis配置
#mybatis:
# # 搜索指定包别名
# typeAliasesPackage: com.tongwei.fundclaim.**.domain
# # 配置mapper的扫描,找到所有的mapper.xml映射文件
# mapperLocations: classpath*:mapper/**/*Mapper.xml
# # 加载全局的配置文件
# configLocation: classpath:mybatis/mybatis-config.xml

新增Mybatis Plus配置。

# MyBatis-Plus配置
mybatis-plus:
config-location: classpath:mybatis/mybatis-config.xml
type-aliases-package: com.tongwei.fundclaim.**.domain
mapper-locations: classpath*:mapper/**/*Mapper.xml

这里只做了一些基础配置,更多高级用法可参照Mybatis Plus官网文档。至此,调整基本完成。咱们可以去验证一下我们的应用是否正常。

既然我们选用了Mybatis Plus,那么代码的生成模版得改改了。这里暂且只需要修改domain.java.vm和mapper.java.vm即可。

亦可根据实际情况作出相应调整。

责任编辑:姜华 来源: 今日头条 若依Mybatis

(责任编辑:焦点)

    推荐文章
    热点阅读