一、@Api 放在类上面:
1、参数:tag 用于描述该类的swagger信息
效果图:2、参数:value 目前没用到,试了下没起作用
二、放在方法上面的@ApiOperation
三、@ApiParam 放在方法上 或者放在方法内
@ApiParam(name = "titalName", value = "名字", required = true) @RequestParam(value = "titalName") String name
value = "名字" 对方法内参数的介绍
PS:@ApiParam的name变量 必须和@RequestParam内的value/name的值保持一值。
@ApiImplicitParams和@ApiParam使用很相似
@ApiOperation(value = "对方法的描述", notes = "提示该方法的使用信息", tags = "方法2")
@GetMapping("/test_code")
// @ApiImplicitParams({
// @ApiImplicitParam(paramType = "query", name = "age", value = "年龄", required = true, dataType ="int"),
// @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "String")
//
// })
public String show(@ApiParam(name = "name", value = "名字", required = true, defaultValue = "test参数")
@RequestParam(value = "name") String name,
@ApiParam(name = "age", type = "int", required = true, defaultValue = "18")
@RequestParam(value = "age") Integer age) {
return name + ": " + age;
}
坑!!!!
swagger版本问题 我用的是2.9.2版本
1、dataType="int" 或者 dataType="Int"
2、dataType="Integer"
点击 execute后 显示age参数有问题 无法访问后端接口。
更换版本—使用2.8.0版本
dataType="Integer" 也是相同问题
但是 dataType = "int" 或者 dataType = "Int" 是可以使用的
建议使用2.8.0版本
io.springfox springfox-swagger22.8.0 io.springfox springfox-swagger-ui2.8.0



