Ruoyi separated version—use Knife4j to automatically generate interface documents

background:

For front-end and back-end separation programs, if front-end developers and back-end developers are required to cooperate in development, the interface document needs to be made explicit to the front-end personnel.

Solution:

Use knife4j to replace the swagger that comes with Ruoyi, because knife4j is packaged on the basis of swagger. Knife4j not only has a friendly interface, but also is easy to use. It also provides enhanced functions such as interface testing and Mock data generation, which can greatly improve developers' productivity. Work efficiency.

The effect is as follows:

Specific steps:

1, ruoyi-admin\pom.xmlModule adds integration dependencies

<!-- knife4j -->
<dependency>
	<groupId>com.github.xiaoymin</groupId>
	<artifactId>knife4j-spring-boot-starter</artifactId>
	<version>3.0.3</version>
</dependency>

2, repair ry-ui\views\tool\swagger\index.vuejumping ground site

url: process.env.VUE_APP_BASE_API + "/doc.html",

3. Modify ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java

createRestApi function, comment out .pathMapping(pathMapping);
              
   

 4. Log in to the system and access the menu system tools/system interface. If the following picture appears, it indicates success.

5. Add @ApiModelProperty(value = "User serial number", required = false) to the field in the SysUser class


    /** 用户ID */
    @ApiModelProperty(value = "用户序号", required = false)
    @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
    private Long userId;

    /** 部门ID */
    @ApiModelProperty(value = "部门编号", required = false)
    @Excel(name = "部门编号", type = Type.IMPORT)
    private Long deptId;

6. Add @ApiOperation("Get user list") to SysUserController

   /**
     * 获取用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @ApiOperation("获取用户列表")
    @GetMapping("/list")
    public TableDataInfo list(SysUser user)
    {
        System.out.println(user.getNickName());
        startPage();
        List<SysUser> list = userService.selectUserList(user);
        return getDataTable(list);
    }

7. Restart, enter the system interface page, and configure the Host as the local address in the personalized settings, otherwise the interface address is incorrect.

8. Open the ""Get user details based on user number"" interface, enter the userId value, and click Send. If the affected content is correct, it will be ok.

Guess you like

Origin blog.csdn.net/zhaolulu916/article/details/134315398