所有分类
  • 所有分类
  • 未分类

Swagger-注解大全

简介

本文介绍Swagger的注解的用法。

注解大全

注解作用示例
@Api用在Controller类上@Api(value = “用户管理类”, description = “Operations about user”)
@ApiIgnore用在类、方法、参数上。表示不为此Controller生成swagger接口@ApiIgnore
@ApiOperation用在Controller方法上@ApiOperation(
          value = “Find purchase order by ID”,
          notes = “For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions”,
          response = Order,
          tags = {“Pet Store”})
@ApiImplicitParam用在Controller方法上或者@ApiImplicitParams里。给方法入参增加说明@ApiImplicitParam(name = “user”, value = “用户详细实体user”, required = true, dataType = “User”)
@ApiImplicitParams用在Controller方法上。给方法入参增加说明@ApiImplicitParams({
            @ApiImplicitParam(name = “id”, value = “用户ID”, required = true, dataType = “Long”),
            @ApiImplicitParam(name = “user”, value = “用户详细实体user”, required = true, dataType = “User”)
    })
@ApiParam可用在Controller方法、参数、属性上。public ResponseEntity<User> createUser(@RequestBody @ApiParam(value = “Created user object”, required = true)  User user)
@ApiResponse用在controller的方法上或者@ApiResponses里@ApiResponse(code = 400, message = “Invalid user supplied”)
@ApiResponses用在controller的方法上@ApiResponses({
        @ApiResponse(code = CommonStatus.OK, message = “操作成功”),
        @ApiResponse(code = CommonStatus.EXCEPTION, message = “服务器内部异常”),
        @ApiResponse(code = CommonStatus.FORBIDDEN, message = “权限不足”)
})
@ResponseHeader用在controller的方法上@ResponseHeader(name=”head1″,description=”response head conf”)
@ApiModel用在返回对象类上@ApiModel
@ApiModelProperty用在返回对象类的属性@ApiModelProperty(notes = “错误消息”)

@ApiImplicitParam

属性取值作用
paramType查询参数类型。此参数和@RequestBody冲突,最好不用
path以地址的形式提交数据
query直接跟参数完成自动映射赋值
body以流的形式提交 仅支持POST
header参数在request headers 里边提交
form以form表单的形式提交。仅支持POST
dataType参数的数据类型 只作为标志说明,并没有实际验证
Long
String
name接收参数名
value接收参数的意义描述
required参数是否必填
true必填
false非必填
defaultValue默认值

0

评论0

请先

显示验证码
没有账号?注册  忘记密码?

社交账号快速登录