API details
Annotation Summary
Scope | API | utilized location |
---|---|---|
object properties | @ApiModelProperty | Used on fields of incoming and outgoing parameter objects |
Protocol Set Description | @Api | Used on the controller class |
Protocol description | @ApiOperation | Used in the controller method |
Response集 | @ApiResponses | Used in the controller method |
Response | @ApiResponse | Used in @ApiResponses |
non-object parameter set | @ApiImplicitParams | Used in the controller method |
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 Recommended configuration for this annotation
value
method
produces
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) {
- 1
- 2
- 3
- 4
- 5
- 6
- 7
@ApiModelProperty(value = "标题")
private String title;
- 1
- 2
@ApiImplicitParam
Attributes | value | effect |
---|---|---|
paramType | query parameter type | |
path | Submit data in the form of 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 as a 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 | Not required | |
defaultValue | Defaults |
Detailed paramType example
path
@RequestMapping(value = "/findById1/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@PathVariable(name = "id") Long id
- 1
- 2
- 3
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之后流就会关闭了)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
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);
}
- 1
- 2
- 3
- 4
- 5
- 6
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)
- 1
- 2
Copyright statement: This article is an original article by the blogger and cannot be reprinted without the permission of the blogger. Please attach a link to the original text to indicate the source. https://blog.csdn.net/xupeng874395012/article/details/68946676