Swagger常用註解
@Api(swagger類屬性設置,註釋在類上)
@Api(tags = "測試類(名稱字段)",description = "測試接口(描述字段)",value = "值")
public class TestController
- 效果
@ApiOperation(swagger方法屬性設置,註釋在方法上)
@ApiOperation(tags = "接口標籤",value = "測試接口")
@PostMapping("/test")
public QYResponse test(){
QYResponse qyResponse = new QYResponse(0,"success","成功");
return qyResponse;
}
- 效果
@ApiIgnore(swagger忽略方法,註釋在方法上)
@ApiOperation("配置文件引用測試")
@ApiIgnore(value = "忽略")
@PostMapping("/test3")
public QYResponse test3() throws IllegalAccessException, InstantiationException {
Animal animal = Animal.class.newInstance().getDog();
QYResponse qyResponse = new QYResponse(0,animal.getName(),"成功");
return qyResponse;
}
- 效果
沒有test3
@ApiModel(參數實體、返回實體信息設置,註釋在類上)
@ApiModel(value = "返回實體",description = "實體描述")
public class QYResponse {
- 效果
@ApiModelProperty(參數實體、返回實體字段設置,註釋在字段上)
@ApiModel(value = "返回實體",description = "實體描述")
public class QYResponse {
@ApiModelProperty(value = "code字段值",name = "code字段名稱")
private int code;
@ApiModelProperty(value = "msg字段值",name = "msg字段名稱")
private String msg;
}
@Data
@ApiModel(value = "Code參數",description = "描述;用於傳遞參數")
public class CodeDTO {
@ApiModelProperty(name = "code字段",value = "描述;code參數字段描述")
String code;
@ApiModelProperty(name = "name字段",value = "值是什麼")
String name;
}
- 效果
@ApiParam(參數設置,註釋在返回參數上)
public QYResponse test2(@RequestBody @ApiParam(value = "參數值",name = "參數名稱") CodeDTO codeDTO){
- 效果