• Ruoyi-Cloud-增加单元测试和Mybatis-plus


    Ruoyi-Cloud-增加单元测试和Mybatis-plus

    目的:

    在RuoYiSystem模块中增加Mybatis-Plus和单元测试

    Mybatis-Plus

    参考:http://doc.ruoyi.vip/ruoyi/document/cjjc.html#集成mybatis-plus实现mybatis增强

    重点是添加依赖后要在nacos中修改application.yml配置

    主要步骤:

    • 在ruoyi-system的pom.xml中增加依赖
    <!-- mybatis-plus -->
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
    </dependency>
    
    • 修改nacos中的application.yml

    • 增加mybatis-plus的configuration

      image-20210612165701435

    • 修改实体类的基类:

      由于原来的BaseEntity中有一些与数据库无关的属性,需要使用注解将其标识为@TableField(exist = false),而此类在的公共模块中并不依赖Mybatis-Plus,所以,可以复制一个基类名为MbpBaseEntity,放在ruoyi-system中,再将需要使用Mybatis-plus的实体类继承此类。

      /**
       * 菜单权限表 sys_menu
       * 
       * @author ruoyi
       */
      public class SysMenu extends MbpBaseEntity
      {
          private static final long serialVersionUID = 1L;
      
          /** 菜单ID */
          private Long menuId;
      
          /** 菜单名称 */
          private String menuName;
      
          @TableField(exist = false)
          /** 父菜单名称 */
          private String parentName;
      
          @TableField(exist = false)
          /** 父菜单ID */
          private Long parentId;
          ……
      }
      

    单元测试

    在ruoyi-modules-system模块的pom.xml中增加以下依赖即可:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13.1</version>
        <scope>test</scope>
    </dependency>
    

  • 相关阅读:
    uniapp中的跳转传参
    图解排序算法(三)之堆排序
    serverlesss
    kvm
    用户态和内核态的理解和区别
    MySQL优化十大技巧
    不懂数据库索引的底层原理?那是因为你心里没点b树
    让你的 Linux 命令骚起来
    史上最简约的vi教程
    mysql 四种隔离级别
  • 原文地址:https://www.cnblogs.com/ShineTan/p/14878592.html
Copyright © 2020-2023  润新知