若依微服务版之集成Mybatis-Plus和Lombok

2023-05-16

目录

  • 一、修改根目录 pom.xml
  • 二、修改 ruoyi-common-core 的 pom.xml
  • 三、去掉 nacos 配置文件中的 mybatis 配置,添加 mybatis-plus 配置
  • 四、添加配置类并注入
  • 五、注入类
  • 六、启动验证


一、修改根目录 pom.xml

添加:

<properties>
    <mybatis-plus.version>3.5.3.1</mybatis-plus.version>
    <lombok.version>1.18.24</lombok.version>
</properties>

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

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>${lombok.version}</version>
</dependency>

二、修改 ruoyi-common-core 的 pom.xml

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

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>

三、去掉 nacos 配置文件中的 mybatis 配置,添加 mybatis-plus 配置

# mybatis配置
# mybatis:
#     # 搜索指定包别名
#     typeAliasesPackage: com.ruoyi.system
#     # 配置mapper的扫描,找到所有的mapper.xml映射文件
#     mapperLocations: classpath:mapper/**/*.xml

# mybatis-plus配置
mybatis-plus:
    # 搜索指定包别名
    typeAliasesPackage: com.ruoyi.*
    # 配置mapper的扫描,找到所有的mapper.xml映射文件
    mapper-locations: classpath:mapper/**/*.xml

四、添加配置类并注入

config 目录和 配置类 MybatisPlusConfig 均为新增:
在这里插入图片描述
MybatisPlusConfig.java 内容如下:

package com.ruoyi.common.core.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();
    }
}

五、注入类

在这里插入图片描述
注入内容为:

com.ruoyi.common.core.config.MybatisPlusConfig

六、启动验证

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

若依微服务版之集成Mybatis-Plus和Lombok 的相关文章

随机推荐

  • geth客户端安装

    geth是以太坊的官方客户端 xff0c 它是一个命令行工具 xff0c 提供很多命令和选项 xff0c 可以运行以太坊节点 创建和管理账户 发送交易 挖矿 部署智能合约等 下面介绍geth的三种安装方法 xff1a 直接下载可执行文件 在
  • win系统下,利用goland来build生成geth.exe可执行文件

    golang环境搭建 具体安装方法就不再赘述 xff0c 但是以太坊对golang的版本有要求 xff0c 得1 7及以上 xff0c 推荐1 9 3 go ethereum代码下载 可以直接访问https github com ether
  • 删除容器命令

    删除容器使用 docker rm 命令 1 删除容器 1 首先需要停止所有的容器 docker stop docker ps a q 2 删除所有的容器 只删除单个时把后面的变量改为container id即可 docker rm dock
  • 正则 (?:)

    X 在正 则中表示所匹配的子组X不作为结果输出 正常情况 X 中的X会被作为新增的一个组序号输出 xff0c 比如 A B xff0c A的序号1 B的序号2 如果 A B xff0c A将没有序号不输出 B的序号为1 规范化url xff
  • 用maven-replacer插件选择正则表达式替换

    在前端html或者jsp中会引入一些诸如css js等静态资源 xff0c 但是有时候浏览器会有缓存 xff0c 更新js后 xff0c 返现一些用户看到的仍然是旧的 xff0c 说明没有生效 这样的话一般是在引入静态资源的时候添加时间戳
  • 【LeetCode股票买卖系列:123. 买卖股票的最佳时机 III 暴力递归=>记忆化搜索=>动态规划】

    x1f680 算法题 x1f680 x1f332 算法刷题专栏 面试必备算法 面试高频算法 x1f340 x1f332 越难的东西 越要努力坚持 xff0c 因为它具有很高的价值 xff0c 算法就是这样 x1f332 作者简介 xff1a
  • [模版]线段树

    span class token macro property span class token directive hash span span class token directive keyword include span spa
  • 判断是否属于同一子网

    include lt bits stdc 43 43 h gt using namespace std int main char a 10 b1 10 b2 10 while scanf 34 s s s 34 a b1 b2 61 EO
  • 单点登录之cas6.5安装部署

    目录 一 准备工作二 安装 jdk11三 安装gradle三 安装tomcat四 下载cas并编译五 部署六 访问 一 准备工作 需要的包 xff1a jdk11 tomcat9 GRADLE7 2 cas overlay template
  • 单点登录之cas集成禅道

    目录 一 前言二 添加应用 xff0c 开启免密登录三 请求格式 一 前言 禅道11 5 1版本开始 xff0c 增加了第三方应用免密登录禅道的功能 xff0c 可以利用此功能实现单点登录 二 添加应用 xff0c 开启免密登录 三 请求格
  • Oracle ora-12514报错解决方法

    目录 一 问题描述二 解决方法 一 问题描述 Oracle 报错 ora 12514 二 解决方法 修改 tnsnames ora xff0c 一般在 D oracle product 10 2 0 client 1 NETWORK ADM
  • “你需要来自XXX的权限才能对此文件夹进行更改”的解决方法

    目录 一 问题描述二 解决方法1 方法1 xff1a 鼠标右键文件夹 xff0c 选择 属性 gt 安全 选项卡 xff0c 对用户进行授权2 方法2 xff1a 选择 高级 xff0c 更改所有者 xff0c 并添加至权限条目3 方法3
  • windows10获取超级管理员权限

    目录 一 新建文本文件 xff0c 命名为带 reg后缀的文件 xff0c 添加以下内容二 鼠标双击运行三 鼠标右键要获取权限的文件夹 xff0c 选择 获取超级管理员权限 一 新建文本文件 xff0c 命名为带 reg后缀的文件 xff0
  • python2.7安装

    目录 一 下载二 安装三 设置环境变量四 验证 一 下载 1 通过 python 官网 https www python org 找到 2 7 版本进行下载 xff1a https www python org downloads rele
  • sharding报错no table route info

    目录 一 问题描述二 解决方法 一 问题描述 集成 sharding 执行数据库操作报错 xff1a no table route info 二 解决方法 一般为分库分表策略配置错误 xff0c 请检查 application yml 文件
  • Nginx配置http跳转https

    目录 一 return 301二 rewrite三 497 状态码四 meta 刷新 Nginx 可通过多种方式实现 http 跳转 https xff0c 以下列出各种方式的实现方法 一 return 301 这是 Nginx 新版本的写
  • OpenFlow网络、OpenFlow交换机及OpenFlow协议的知识总结

    目录 OpenFlow起源与发展 OpenFlow网络 1 OpenFlow交换机 xff1a 2 FlowVisor xff1a 3 Controller xff1a OpenFlow交换机 分类 安全通道 流表 OpenFlow协议 x
  • 【高效运维】Jenkins之uni-app自动化部署

    目录 一 前言二 使用 Pipeline 创建任务1 创建一个流水线任务2 配置流水线 xff08 1 xff09 配置构建触发器 xff08 2 xff09 配置流水线 xff08 Pipeline script from SCM xff
  • Windows下安装Redis7.0.8

    目录 一 下载二 解压三 启动服务四 客户端连接测试五 把 redis 安装到服务1 安装2 启动服务3 停止服务4 卸载服务 一 下载 官网上没有 windows 版本的 redis 下载 xff0c 需要到 github 下载 xff1
  • 若依微服务版之集成Mybatis-Plus和Lombok

    目录 一 修改根目录 pom xml二 修改 ruoyi common core 的 pom xml三 去掉 nacos 配置文件中的 mybatis 配置 xff0c 添加 mybatis plus 配置四 添加配置类并注入五 注入类六