Swagger2如何使用更好?

知道了swagger2的好,但要怎样的好好利用,才能好上加好?

1,用swagger2注解代替掉字段注释吧

为什么这样说,字段注释是我们写来解释字段含义的

public class PageVO {

    /**
     * 第几页
     */
    private Integer current;

    /**
     * 每页条数
     */
    private Integer size;
}

这样写,没毛病,但是就只能我们自己看。

@ApiModel(description = "分页入参模型")
public class PageVO {
    
    @ApiModelProperty(value = "第几页")
    private Integer current;

    @ApiModelProperty(value = "每页条数")
    private Integer size;
}

而这样写,不仅我们自己能看,swagger2还能依据这些注解生成出文档给别人看,就不用再写接口文档了。

2,把注解写全,当做接口文档来写

@ApiModel(description = "分页入参模型")
public class PageVO {
    
    @ApiModelProperty(value = "第几页",required = true,example = "1")
    private Integer current;

    @ApiModelProperty(value = "每页条数",required = true,example = "10")
    private Integer size;
}

不用多说,写的越全,自己看的明白,别人也更明白。

3,换一个更好看的swagger-ui

个人觉得自带的swagger-ui很丑,有人也这么觉得,所以有人改进了swagger界面。

有点丑
在这里插入图片描述
怎么换呢?

        <!--https://doc.xiaominfo.com/knife4j/-->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
            <version>${knife4j.version}</version>
        </dependency>

引入这个依赖,将
http://localhost:20001/swagger-ui.html
改成
http://localhost:20001/doc.html

o了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值