赞
踩
0、请先配置好swagger-ui 的依赖等,
1、配置文件
@EnableSwaggerBootstrapUI @EnableSwagger2 @Configuration public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()).build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("工作计划") .description("工作计划详细描述") .version("0.0.1") .build(); } }
2、注解使用
@PostMapping("/createOrder421")
@ApiOperation(value = "fastjson-JSONObject-动态创建显示参数")
@ApiOperationSupport(params = @DynamicParameters(name = "CreateOrderModel",properties = {
@DynamicParameter(name = "id",value = "注解id",example = "X000111",required = true,dataTypeClass = Integer.class),
@DynamicParameter(name = "name",value = "订单编号",required = false)
}))
public Rest<JSONObject> createOrder12222(@RequestBody JSONObject jsonObject){
Rest<JSONObject> r=new Rest<>();
r.setData(jsonObject);
return r;
}
@PostMapping("/createOrder422")
@ApiOperation(value = "jdk-Map-动态创建显示参数")
@DynamicParameters(name = "CreateOrderMapModel",properties = {
@DynamicParameter(name = "id",value = "注解id",example = "X000111",required = true,dataTypeClass = Integer.class),
@DynamicParameter(name = "name",value = "订单编号"),
@DynamicParameter(name = "name1",value = "订单编号1"),
@DynamicParameter(name = "orderInfo",value = "订单信息",dataTypeClass = Order.class),
})
public Rest<Map> createOrder12232(@RequestBody Map map){
Rest<Map> r=new Rest<>();
r.setData(map);
return r;
}
//我自己的 复制红色的即可
@ApiOperation(value = "入參json ok", response = Result.class)
@DynamicParameters(name = "CreateOrderModel", properties = {
@DynamicParameter(name = "id", value = "注解id", example = "X000111", required = true, dataTypeClass = Integer.class),
@DynamicParameter(name = "name", value = "订单编号", required = false), }) @PostMapping("/postjson3")
public String postjson3(@RequestBody JSONObject json) {
try {// 参数验证 String[] keys = {"id", "name"};
ValidateJson.validate(json, keys);
return json.getString("name");
} catch (ValidateJsonException e) {
e.printStackTrace();
}
return "123";
}
//也可看这个文章
Swagger-boostrap-ui Map/JSONObject -动态创建显示参数_墨着染霜华的博客-CSDN博客_swagger 动态参数
https://blog.csdn.net/chengmin123456789/article/details/108345669
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。