Aidex Sharp是基于RuoYi-Vue的一个SpringBoot快速开发框架,我比较喜欢的是他目前的代码生成器,时开源产品中做的比较细的。支持各种校验和用户、部门选择组件间的自动生成,看介绍以后还会支持工作流,多租户。并且有uniapp的手机版本。
因为基于若依,整体架构比较简单。适合小白学习。
先上下载地址:https://gitee.com/big-hedgehog/aidex-sharp
不过我不太喜欢写个业务就去改mapper.xml,所以想整合上mybatis-plus,方便以后使用。下面把整合方法分享给大家。。
若依官网参考:集成mybatisplus实现mybatis增强
比较简单的流程,如果要满足更多需求请自行优化:)
1.在项目根目录增加mybatis-plus 依赖
<!-- mybatis-plus 增强CRUD -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
2.aidex-common\pom.xml 增加依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
3.aidex-admin
文件application.yml
,增加mybatis-plus配置
(官网说修改mybatis为mybatis-plus,我保留了)
# MyBatis配置
mybatis:
# 搜索指定包别名
typeAliasesPackage: com.aidex.**.domain,com.aidex.**.entity,com.aidex.**.po
# 配置mapper的扫描,找到所有的mapper.xml映射文件
mapperLocations: classpath*:mapper/**/*Mapper.xml,classpath*:com/aidex/**/mapper/*Mapper.xml
# 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml
# 加载全局的配置文件
dbName: oracle
# 是否显示拦截器输出sql
isShowMyBatisSql: true
# MyBatis-plus配置
mybatis-plus:
# 搜索指定包别名
typeAliasesPackage: com.aidex.**.domain,com.aidex.**.entity,com.aidex.**.po
# 配置mapper的扫描,找到所有的mapper.xml映射文件
mapperLocations: classpath*:mapper/**/*Mapper.xml,classpath*:com/aidex/**/mapper/*Mapper.xml
# 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml
# 加载全局的配置文件
dbName: oracle
# 是否显示拦截器输出sql
isShowMyBatisSql: true
4.在aidex.frameword.cofng中添加添加Mybatis Plus
配置MybatisPlusConfig.java
。 PS:原来的MyBatisConfig.java
需要删除掉,也可以注释掉。
package com.aidex.framework.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Mybatis Plus 配置
*
* @author ruoyi
*/
@EnableTransactionManagement(proxyTargetClass = true)
@Configuration
public class MybatisPlusConfig
{
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor()
{
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 分页插件
interceptor.addInnerInterceptor(paginationInnerInterceptor());
// 乐观锁插件
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
// 阻断插件
interceptor.addInnerInterceptor(blockAttackInnerInterceptor());
return interceptor;
}
/**
* 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html
*/
public PaginationInnerInterceptor paginationInnerInterceptor()
{
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
// 设置数据库类型为mysql
paginationInnerInterceptor.setDbType(DbType.MYSQL);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
paginationInnerInterceptor.setMaxLimit(-1L);
return paginationInnerInterceptor;
}
/**
* 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html
*/
public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor()
{
return new OptimisticLockerInnerInterceptor();
}
/**
* 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html
*/
public BlockAttackInnerInterceptor blockAttackInnerInterceptor()
{
return new BlockAttackInnerInterceptor();
}
}
5.找到aidex.common.mapper 中的 BaseMapper.java ,改为集成mybatis-plus类
修改后如下
public interface BaseMapper<T> extends com.baomidou.mybatisplus.core.mapper.BaseMapper<T> {
致此aidex整合mybatis-plus完成。
你也可以在BaseMapper中添加自己想实现的通用方法
//得到列表
List<T> selectList() {
return this.selectList(new QueryWrapper<>());
}
/**
* 批量插入或更新
*/
boolean insertOrUpdateBatch(Collection<T> entityList) {
return insertOrUpdateBatch(entityList, 1000);
}
///更多方法
问题,mybatis-plus添加依赖以后,总提示包不存在
一定注意,依赖要同时添加到根目录和aidex-common目录中的pom.xml中
并且在添加后重载
重载后查看外部库中是否存在mytatis-plus的相关包