学习swagger总结

一、@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版本

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>

补充:

下图效果图

当@Api的tags和@ApiOperation内的tags不相同时

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
@ApiModel(value = "UpdateOrCreatePodNumaAffinityParam", description = "策略配置类")
public class UpdateOrCreatePodNumaAffinityParam {
    @ApiModelProperty(name = "node_id", value = "节点Id", required = true)
    private Integer nodeId;

    @ApiModelProperty(name = "cpu_number", value = "cpu核")
    private double cpuNumber;
    @ApiModelProperty(name = "memory_gb", value = "内存")
    private double memoryGB;
    @ApiModelProperty(name = "cpu_allocation_rate", value = "cpu售卖率")
    private int cpuAllocationRate;
    @ApiModelProperty(name = "memory_allocation_rate", value = "内存售卖率")
    private int memoryAllocationRate;
    @ApiModelProperty(name = "update_reason", value = "变更原因")
    private String updateReason;
}

下图效果图

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值