準備工作:
3 Swagger與標準RestFul(POST、PUT、DELETE、GET)集成Demo【以App應用模塊爲例】
或:
@ApiOperation(value = "創建", notes = "") @RequestMapping(value = "/release",method = RequestMethod.POST) public ResponseData newApp(@ApiParam(name="app",
value="產品臨時對象",required = true) @RequestBodyApp app){
@ApiOperation(value = "獲取產品詳情", notes = "產品詳情") @ApiImplicitParam(paramType = "path", name = "appId", value = "產品appId", required = true, dataType = "String") @RequestMapping(value = "/{appId}", method = RequestMethod.GET) private App getAppDetail(@PathVariable("appId") String appId) {
//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) {
//Post Many app objects
@ApiOperation:描述一個類的一個方法,或者說一個接口
@ApiParam:單個參數描述
@ApiModel:用對象來接收參數
@ApiProperty:用對象接收參數時,描述對象的一個字段
@ApiResponses:HTTP響應整體描述
@ApiIgnore:使用該註解忽略這個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 */