}
或:
@ApiOperation(value = "創(chuàng)建", notes = "")
@RequestMapping(value = "/release",method = RequestMethod.POST)
public ResponseData newApp(@ApiParam(name="app",value="產(chǎn)品臨時(shí)對(duì)象",required = true) @RequestBodyApp app){ //todo
reutrn app;
}
//2 GET (多條件查詢(xún)分頁(yè))--- URL:/apps
@ApiOperation(value = "應(yīng)用查詢(xún)", notes = "")
@ApiImplicitParams( value = {
@ApiImplicitParam(paramType = "query", name = "appType", dataType = "String", required = true, value = "應(yīng)用類(lèi)型", defaultValue = "10"),
@ApiImplicitParam(paramType = "query", name = "appClassId", dataType = "String", required = true, value = "應(yīng)用分類(lèi)id"),
@ApiImplicitParam(paramType = "query", name = "appId", dataType = "String", required = true, value = "appId"),
@ApiImplicitParam(paramType = "query", name = "appName", dataType = "String", value = "應(yīng)用名稱(chēng)"),
@ApiImplicitParam(paramType = "query", name = "appStatus", dataType = "String", required = true, value = "狀態(tài) 0:已下架 1:正常"),
@ApiImplicitParam(paramType = "query",name = "page", value = "當(dāng)前頁(yè)碼", required = true, dataType = "integer"),
@ApiImplicitParam(paramType = "query",name = "rows", value = "每頁(yè)條數(shù)", required = true, dataType = "integer")
})
@RequestMapping(method = RequestMethod.GET)
public App list(@RequestParam("appType") String appType,@RequestParam("appClassId") String appClassId,@RequestParam("appId") String appId,@RequestParam("appName") String appName,
@RequestParam("appStatus") String appStatus,
@RequestParam(name = "page", defaultValue = "1") int page,
@RequestParam(name = "rows", defaultValue = "10") int rows) {
//todo
return 按規(guī)范自己封裝;
}
//3 get ---url/{appid}
@ApiOperation(value = "獲取產(chǎn)品詳情", notes = "產(chǎn)品詳情")
@ApiImplicitParam(paramType = "path", name = "appId", value = "產(chǎn)品appId",
required = true, dataType = "String")
@RequestMapping(value = "/{appId}", method = RequestMethod.GET)
private App getAppDetail(@PathVariable("appId") String appId) {
//todo
return 按規(guī)范自己封裝;
}
//4 PUT --URL/{appId} and RequestBody
@ApiOperation(value="update", notes="")
@ApiImplicitParams( value = {
@ApiImplicitParam(paramType = "path", name = "appId", value = "", required = true, dataType = "String"),
@ApiImplicitParam(name = "app", value = "App", required = true, dataType = "App")
})
@RequestMapping(value = "/{appId}", method = RequestMethod.PUT , consumes = MediaTypes.JSON_UTF_8)
public App Appupdate(@PathVariable(value = "appId") String appId,@RequestBody App app) { //todo
return 按規(guī)范自己封裝;
}
//Post Many app objects
@ApiOperation(value="創(chuàng)建多條APPs", notes="")
@RequestMapping(value="/postApps", method=RequestMethod.POST)
public String postApps(@ApiParam(name="apps",value="用戶s",required = true) @RequestBody List<App> apps) {
System.out.print(apps);
return "success";
}
4 常見(jiàn)swagger注解一覽與使用
最常用的5個(gè)注解
@Api:修飾整個(gè)類(lèi),描述Controller的作用
@ApiOperation:描述一個(gè)類(lèi)的一個(gè)方法,或者說(shuō)一個(gè)接口
@ApiParam:?jiǎn)蝹€(gè)參數(shù)描述
@ApiModel:用對(duì)象來(lái)接收參數(shù)
@ApiProperty:用對(duì)象接收參數(shù)時(shí),描述對(duì)象的一個(gè)字段
其它若干
@ApiResponse:HTTP響應(yīng)其中1個(gè)描述
@ApiResponses:HTTP響應(yīng)整體描述
@ApiIgnore:使用該注解忽略這個(gè)API
@ApiClass
@ApiError @ApiErrors
@ApiParamImplicit @ApiParamsImplicit
/**@ApiParam:
* Adds additional meta-data for operation parameters.
* <p/> * This annotation can be used only in combination of JAX-RS 1.x/2.x annotations. */
/**@ApiParamImplicit:
* Represents a single parameter in an API Operation.
* <p/> * While {@link ApiParam} is bound to a JAX-RS parameter, * method or field, this allows you to manually define a parameter in a fine-tuned manner. * This is the only way to define parameters when using Servlets or other non-JAX-RS * environments. * <p/> * This annotation must be used as a value of {@link ApiImplicitParams} * in order to be parsed. * * @see ApiImplicitParams */
5 Swagger 使用參考網(wǎng)址
Swagger RESTful API Documentation Specification: