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>

posted @ 2021-06-12 17:05  一 缕 阳 光  阅读(2343)  评论(0编辑  收藏  举报