当前位置:网站首页>swagger常用注释API @ApiModel、@ApiModelProperty的用法
swagger常用注释API @ApiModel、@ApiModelProperty的用法
2022-08-11 05:29:00 【zhangkai__】
API详细说明
注释汇总
| 作用范围 | API | 使用位置 |
|---|---|---|
| 对象属性 | @ApiModelProperty | 用在出入参数对象的字段上 |
| 协议集描述 | @Api | 用于controller类上 |
| 协议描述 | @ApiOperation | 用在controller的方法上 |
| Response集 | @ApiResponses | 用在controller的方法上 |
| Response | @ApiResponse | 用在 @ApiResponses里边 |
| 非对象参数集 | @ApiImplicitParams | 用在controller的方法上 |
| 非对象参数描述 | @ApiImplicitParam | 用在@ApiImplicitParams的方法里边 |
| 描述返回对象的意义 | @ApiModel | 用在返回对象类上 |
@RequestMapping此注解的推荐配置
value
method
produces
示例:
@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
| 属性 | 取值 | 作用 |
|---|---|---|
| paramType | 查询参数类型 | |
| path | 以地址的形式提交数据 | |
| query | 直接跟参数完成自动映射赋值 | |
| body | 以流的形式提交 仅支持POST | |
| header | 参数在request headers 里边提交 | |
| form | 以form表单的形式提交 仅支持POST | |
| dataType | 参数的数据类型 只作为标志说明,并没有实际验证 | |
| Long | ||
| String | ||
| name | 接收参数名 | |
| value | 接收参数的意义描述 | |
| required | 参数是否必填 | |
| true | 必填 | |
| false | 非必填 | |
| defaultValue | 默认值 |
paramType 示例详解
path
@RequestMapping(value = "/findById1/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@PathVariable(name = "id") Long idbody
@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)转自 https://blog.csdn.net/chinassj/article/details/81875038,十分感谢~
边栏推荐
猜你喜欢

The official website of OpenMLDB is upgraded, and the mysterious contributor map will take you to advance quickly

Wonderful linkage | OpenMLDB Pulsar Connector principle and practical operation

127.0.0.1 已拒绝连接

Day 78

Day 83

Thesis unscramble TransFG: A Transformer Architecture for Fine - grained Recognition

本地缓存cookie的使用

JS进阶网页特效(pink老师笔记)

Open Source Machine Learning Database OpenMLDB Contributor Program Fully Launched

使用adb命令管理应用
随机推荐
OpenMLDB + Jupyter Notebook: Quickly Build Machine Learning Applications
无效的修订:3.18.1-g262b901-dirty
Day 71
Promise 中状态改变和回调执行先后顺序 和promise多次回调
The whole process of Tinker access --- Compilation
js learning advanced BOM part (pink teacher notes)
函数使用记录
自己动手写RISC-V的C编译器-01实现加减法
Day 81
基于微信小程序云开发实现的电商项目,可以自行定制开发
Fourth Paradigm OpenMLDB optimization innovation paper was accepted by VLDB, the top international database association
2021-09-11 C language variables and memory allocation
Node stepping on the pit 80 port is occupied
Building a data ecology for feature engineering - Embrace the open source ecology, OpenMLDB fully opens up the MLOps ecological tool chain
OpenMLDB:线上线下一致的生产级特征计算平台
USB in NRZI to encode the data
Getting Started with JNI
Day 87
Some formulas for system performance and concurrency
Regular expression replacement for batch quick modification code