swagger常用註解說明
阿新 • • 發佈:2020-07-29
1、@Api
用在類上,說明該類的作用。
@Api(tags = "BsFieldController",description = "Field相關介面")
2、@ApiOperation
用在方法上,說明方法的作用
@ApiOperation(value = "BsField條件分頁查詢",notes = "分頁條件查詢BsField方法詳情",tags = {"BsFieldController"})
3、@ApiImplicitParams
用在方法上包含一組引數說明
4、@ApiImplicitParam
表示單獨的請求引數
@ApiOperation(value = "BsField條件分頁查詢",notes = "分頁條件查詢BsField方法詳情",tags = {"BsFieldController"}) @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "page", value = "當前頁", required = true, dataType = "Integer"), @ApiImplicitParam(paramType = "path", name = "size", value = "每頁顯示條數", required = true, dataType = "Integer") }) @PostMapping(value = "/search/{page}/{size}" ) public Result<List<BsField>> findPage(@RequestBody(required = false) @ApiParam(name = "BsField物件",value = "傳入JSON資料",required = false) BsField bsField, @PathVariable int page, @PathVariable int size){ //呼叫BsFieldService實現分頁條件查詢BsField List<BsField> bsFieldList = bsFieldService.findPage(bsField, page, size); return new Result(StatusCode.OK,"查詢成功",bsFieldList); }
5、@Apiparam
用於方法,引數,欄位說明
/*** * 根據ID查詢BsField資料 * @param id * @return */ @ApiOperation(value = "BsField根據ID查詢",notes = "根據ID查詢BsField方法詳情",tags = {"BsFieldController"}) @GetMapping("/{id}") public Result<BsField> findById(@PathVariable @ApiParam(value = "主鍵ID", required = true) Integer id){ //呼叫BsFieldService實現根據主鍵查詢BsField BsField bsField = bsFieldService.findById(id); return new Result<BsField>(StatusCode.OK,"查詢成功",bsField); }