[Spring]~Swagger常用註解

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){
  • 效果
    在這裏插入圖片描述
    在這裏插入圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章