其他分享
首页 > 其他分享> > Swagger

Swagger

作者:互联网

Swagger

前后端分离开发,后端需要编写接⼝说明⽂档,会耗费⽐较多的时间

swagger是⼀个⽤于⽣成服务器接⼝的规范性⽂档、并且能够对接⼝进⾏测试的⼯具

1.1 作用

1.2 Swagger整合

1.3 Swagger注解说明

swagger提供了⼀套注解,可以对每个接⼝进⾏详细说明

@Api类注解,在控制器类添加此注解,可以对控制器类进⾏功能说明

@Api(value = "提供商品添加、修改、删除及查询的相关接⼝",tags = "商品管理") 

@ApiOperation⽅法注解:说明接⼝⽅法的作⽤

@ApiImplicitParams@ApiImplicitParam⽅法注解,说名接⼝⽅法的参数


@ApiOperation("用户登录接口")
@ApiImplicitParams({
    @ApiImplicitParam(dataType = "string",name = "username", value = "用户登录账号",required = true),
    @ApiImplicitParam(dataType = "string",name = "password", value = "用户登录密码",required = true)
})
@GetMapping("/login")
public ResultVO login(@RequestParam("username") String name,
                      @RequestParam(value = "password") String pwd){
    ResultVO resultVO = userService.checkLogin(name, pwd);
    return resultVO;
}

@ApiModel@ApiModelProperty当接⼝参数和返回值为对象类型时,在实体类中添加注解说明

@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "User对象", description = "⽤户/买家信息")
public class User {
    @ApiModelProperty(dataType = "int", required = false)
    private int userId;
    @ApiModelProperty(dataType = "String", required = true, value = "⽤户注册账号")
    private String userName;
    @ApiModelProperty(dataType = "String", required = true, value = "⽤户注册密码")
    private String userPwd;
    @ApiModelProperty(dataType = "String", required = true, value = "⽤户真实姓名")
    private String userRealname;
    @ApiModelProperty(dataType = "String", required = true, value = "⽤户头像url")
    private String userImg;
}

@ApiIgnore接⼝⽅法注解,添加此注解的⽅法将不会⽣成到接⼝⽂档中

1.4 Swagger-ui 插件

说明:Swagger-ui1.9.6后已经停止更新,作者后续作品:Knife4j

标签:Swagger,String,dataType,value,注解,swagger
来源: https://www.cnblogs.com/royal6/p/16354089.html