当前位置:网站首页>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,十分感谢~
边栏推荐
- 虚拟机更改IP地址
- mongoose连接mongodb不错,显示encoding没有定义
- [Meetup] OpenMLDBxDolphinScheduler engineering and scheduling link link characteristics, building the end-to-end MLOps workflow
- OpenMLDB:线上线下一致的生产级特征计算平台
- js学习进阶BOM部分(pink老师笔记)
- Fourth Paradigm OpenMLDB optimization innovation paper was accepted by VLDB, the top international database association
- JNI入门
- Day 85
- Day 75
- Tinker的自我介绍
猜你喜欢

Building a data ecology for feature engineering - Embrace the open source ecology, OpenMLDB fully opens up the MLOps ecological tool chain

js学习进阶BOM部分(pink老师笔记)

Tinker的自我介绍

Day 76

Real-time Feature Computing Platform Architecture Methodology and Practice Based on OpenMLDB

ARM assembly instruction ADR and LDR

USB URB

Getting Started with JNI

【无标题】

USB in NRZI to encode the data
随机推荐
USB URB
Real-time Feature Computing Platform Architecture Methodology and Practice Based on OpenMLDB
PyQt5中调用.ui转换的.py文件代码解释
Promise.race learning (judging the fastest execution of multiple promise objects)
Node 踩坑之80端口被占用
欧拉法解微分方程
杀死进程-查看防火墙状态
【无标题】
OpenMLDB Pulsar Connector: Efficiently connect real-time data to feature engineering
构建面向特征工程的数据生态 ——拥抱开源生态,OpenMLDB全面打通MLOps生态工具链
Dark Horse Event Project
mount命令--挂载出现只读,解决方案
8-byte standard request parsing during USB enumeration
2021-09-11 C language variables and memory allocation
Day 77
Byte (byte) and bit (bit)
JS进阶网页特效(pink老师笔记)
实时特征计算平台架构方法论和基于 OpenMLDB 的实践
第一章 Verilog语言和Vivado初步使用
Promise.race学习(判断多个promise对象执行最快的一个)