API details
Comment summary
Scope of action | API | utilized location |
---|---|---|
object properties | @ApiModelProperty | Used on the fields of the input and output parameter objects |
protocol set description | @Api | For the controller class |
protocol description | @ApiOperation | Used in the method of the controller |
Response set | @ApiResponses | Used in the method of the controller |
Response | @ApiResponse | Used in @ApiResponses |
non-object parameter set | @ApiImplicitParams | Used in the method of the controller |
Non-object parameter description | @ApiImplicitParam | Used in the method of @ApiImplicitParams |
Describe the meaning of the returned object | @ApiModel | Used on the return object class |
@RequestMapping The recommended configuration
value
method
produces for this annotation
Example:
-
@ApiOperation("信息软删除") @ApiResponses({ @ApiResponse(code = CommonStatus.OK, message = "操作成功"), @ApiResponse(code = CommonStatus.EXCEPTION, message = "服务器内部异常"), @ApiResponse(code = CommonStatus.FORBIDDEN, message = "权限不足") }) @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", dataType = "Long", name = "id", value = "信息id", required = true) }) @RequestMapping(value = "/remove.json", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public RestfulProtocol remove(Long id) {
@ApiModelProperty(value = "标题")
private String title;
@ApiImplicitParam
Attributes | value | effect |
---|---|---|
paramType | query parameter type | |
path | Submit data as an address | |
query | Complete automatic mapping assignment directly with parameters | |
body | Submitting as a stream only supports POST | |
header | Parameters are submitted in request headers | |
form | Submitting in the form of form only supports POST | |
dataType | The data type of the parameter is only used as a flag description, and there is no actual verification | |
Long | ||
String | ||
name | Receive parameter name | |
value | Description of the meaning of the received parameters | |
required | Is the parameter required? | |
true | required | |
false | optional | |
defaultValue | Defaults |
ParamType Example Detailed Explanation
path
@RequestMapping(value = "/findById1/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@PathVariable(name = "id") Long id
body
@ApiImplicitParams({ @ApiImplicitParam(paramType = "body", dataType = "MessageParam", name = "param", value = "信息参数", required = true) })
@RequestMapping(value = "/findById3", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@RequestBody MessageParam param
提交的参数是这个对象的一个json,然后会自动解析到对应的字段上去,也可以通过流的形式接收当前的请求数据,但是这个和上面的接收方式仅能使用一个(用@RequestBody之后流就会关闭了)
header
@ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "Long", name = "id", value = "信息id", required = true) })
String idstr = request.getHeader("id");
if (StringUtils.isNumeric(idstr)) {
id = Long.parseLong(idstr);
}
Form
@ApiImplicitParams({ @ApiImplicitParam(paramType = "form", dataType = "Long", name = "id", value = "信息id", required = true) })
@RequestMapping(value = "/findById5", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
Reposted from https://blog.csdn.net/chinassj/article/details/81875038, thank you very much~