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
-
修改實體類的基類:
由於原來的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>