swagger映射map入参
本帖最后由 maozzs 于 2022-7-22 17:46 编辑1 maven配置,swagger2点几的版本貌似都可以
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
2 附件下载swagger配置类: ApiJsonObject.java ApiJsonProperty.java MapReaderForApi.java
下载完的java文件,粘贴到项目里
3 参考DemoController,入参Map前加@ApiJsonProperty注解就可以啦。
@PostMapping(value = "/demo")
@ApiOperation(value = "获取资产", notes = "入参为map,userId必传")
public String valuationValue(@ApiJsonObject(name = "RequestModel", value = {
@ApiJsonProperty(key = "userId", example = "xsy123", description = "用户Id必传", type = "string", required = true),
@ApiJsonProperty(key = "indexs", example = "1,2", description = "指标编号非必传", type = "string", required = false),
@ApiJsonProperty(key = "queryDate", example = "2018-12-24", description = "查询日期非必传", type = "string", required = false) })
@RequestBody Map<String, Object> params) {
System.out.println(String.format("Method[%s], args[%s]", "demo", params.toString()));
return "";
}
4 亲测有效,看效果。原理是实现了swagger的插件接口。对插件接口进行了重写。
wuxianzhen 发表于 2022-7-22 17:28
代码要简洁,这到处加的去,还不如不加
怪我描述得不太清楚。帖子重新整理了下。审核通过后你再看下哦。超级简单。:$qqq 这样写大可不必啊,参数校验也不方便,实在要用map动态参数要去自定义 :lol偷懒的入参写法
页:
[1]