一、@Api 放在类上面:
1、参数:tag 用于描述该类的swagger信息
效果图:2、参数:value 目前没用到,试了下没起作用
二、放在方法上面的@ApiOperation
三、@ApiParam 放在方法上 或者放在方法内
@ApiParam(name = "titalName", value = "名字", required = true) @RequestParam(value = "titalName") String name
value = "名字" 对方法内参数的介绍
PS:@ApiParam的name变量 必须和@RequestParam内的value/name的值保持一值。
@ApiImplicitParams和@ApiParam使用很相似
@ApiOperation(value = "对方法的描述", notes = "提示该方法的使用信息", tags = "方法2")
@GetMapping("/test_code")
// @ApiImplicitParams({
// @ApiImplicitParam(paramType = "query", name = "age", value = "年龄", required = true, dataType ="int"),
// @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String")
//
// })
public String show(@ApiParam(name = "name", value = "名字", required = true, defaultValue = "test参数")
@RequestParam(value = "name") String name,
@ApiParam(name = "age", type = "int", required = true, defaultValue = "18")
@RequestParam(value = "age") Integer age) {
return name + ": " + age;
}
坑!!!!
swagger版本问题 我用的是2.9.2版本
1、dataType="int" 或者 dataType="Int"
2、dataType="Integer"
点击 execute后 显示age参数有问题 无法访问后端接口。
更换版本—使用2.8.0版本
dataType="Integer" 也是相同问题
但是 dataType = "int" 或者 dataType = "Int" 是可以使用的
建议使用2.8.0版本
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
补充:
下图效果图
当@Api的tags和@ApiOperation内的tags不相同时
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@ApiModel(value = "UpdateOrCreatePodNumaAffinityParam", description = "策略配置类")
public class UpdateOrCreatePodNumaAffinityParam {
@ApiModelProperty(name = "node_id", value = "节点Id", required = true)
private Integer nodeId;
@ApiModelProperty(name = "cpu_number", value = "cpu核")
private double cpuNumber;
@ApiModelProperty(name = "memory_gb", value = "内存")
private double memoryGB;
@ApiModelProperty(name = "cpu_allocation_rate", value = "cpu售卖率")
private int cpuAllocationRate;
@ApiModelProperty(name = "memory_allocation_rate", value = "内存售卖率")
private int memoryAllocationRate;
@ApiModelProperty(name = "update_reason", value = "变更原因")
private String updateReason;
}
下图效果图