@ApiOperation不是spring自帶的注解是swagger里的 com.wordnik.swagger.annotations.ApiOperation;
@ApiOperation和@ApiParam為添加的API相關注解,個參數說明如下:
@ApiOperation(value = “接口說明”, httpMethod = “接口請求方式”, response = “接口返回參數類型”, notes = “接口發布說明”) 其他參數可參考源碼;
@ApiParam(required = “是否必須參數”, name = “參數名稱”, value = “參數具體描述”)
@ApiImplicitParam 用於方法 表示單獨的請求參數
@ApiImplicitParams() 用於方法,包含多個 @ApiImplicitParam
name–參數ming
value–參數說明
dataType–數據類型
paramType–參數類型
example–舉例說明
參考 https://www.2cto.com/kf/201710/692105.html
@ApiResponses
用於表示一組響應
@ApiResponse
用在@ApiResponses中,一般用於表達一個錯誤的響應信息
code:數字,例如400
message:信息,例如”請求參數沒填好”
response:拋出異常的類
實際項目中非常需要寫文檔,提高Java服務端和Web前端以及移動端的對接效率。
Swagger是當前最好用的Restful API文檔生成的開源項目,通過swagger-spring項目
實現了與SpingMVC框架的無縫集成功能,方便生成spring restful風格的接口文檔,
同時swagger-ui還可以測試spring restful風格的接口功能。
參考:https://blog.csdn.net/fansunion/article/details/51923720
詳細文檔參考:https://github.com/swagger-api/swagger-core/wiki/Annotations