基于RuoYi

您所在的位置:网站首页 vue框架介绍 基于RuoYi

基于RuoYi

#基于RuoYi| 来源: 网络整理| 查看: 265

Aidex Sharp是基于RuoYi-Vue的一个SpringBoot快速开发框架,我比较喜欢的是他目前的代码生成器,时开源产品中做的比较细的。支持各种校验和用户、部门选择组件间的自动生成,看介绍以后还会支持工作流,多租户。并且有uniapp的手机版本。

因为基于若依,整体架构比较简单。适合小白学习。

先上下载地址:https://gitee.com/big-hedgehog/aidex-sharp

        

不过我不太喜欢写个业务就去改mapper.xml,所以想整合上mybatis-plus,方便以后使用。下面把整合方法分享给大家。。

若依官网参考:集成mybatisplus实现mybatis增强

比较简单的流程,如果要满足更多需求请自行优化:)

1.在项目根目录增加mybatis-plus 依赖

com.baomidou mybatis-plus-boot-starter 3.4.2

2.aidex-common\pom.xml 增加依赖

com.baomidou mybatis-plus-boot-starter

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 extends com.baomidou.mybatisplus.core.mapper.BaseMapper {

致此aidex整合mybatis-plus完成。

你也可以在BaseMapper中添加自己想实现的通用方法

//得到列表 List selectList() { return this.selectList(new QueryWrapper()); } /** * 批量插入或更新 */ boolean insertOrUpdateBatch(Collection entityList) { return insertOrUpdateBatch(entityList, 1000); } ///更多方法

问题,mybatis-plus添加依赖以后,总提示包不存在

一定注意,依赖要同时添加到根目录和aidex-common目录中的pom.xml中

并且在添加后重载

重载后查看外部库中是否存在mytatis-plus的相关包



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3