Swagger3在线接口文档

使用前配置:

1.引入依赖:

<!--        swagger在线接口文档-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>com.github.xiaoymin</groupId>-->
<!--            <artifactId>swagger-bootstrap-ui</artifactId>-->
<!--            <version>1.9.6</version>-->
<!--        </dependency>-->

2.防止启动报错,配置:

#Swagger3
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER

配置类:

@Configuration
public class Swagger3Config {

    @Bean
    public Docket getDocket(){
        return  new Docket(DocumentationType.OAS_30).apiInfo(getApiInfo());
        /*return  new Docket(DocumentationType.OAS_30)
                .apiInfo(getApiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();*/
    }

    @Bean
    public ApiInfo getApiInfo(){
        return   new ApiInfoBuilder()
                .title("XXX系统-接口文档")
                .description("这是sdy!!!!")
                .contact(new Contact("sdy","http://www.baidu.com","1656088120@qq.com"))
                .version("v1.0")
                .build();
    }
}

3.使用:

实例:

在接口中:

@RestController
//此类接口说明
@Api(tags = "账户管理接口")
public class Swagger3Controller {
    @RequestMapping("/swagger/test1")
//    该接口说明
    @ApiOperation("登录接口")
//    参数说明
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "username",value = "用户名",required = true,dataType = "String"),
            @ApiImplicitParam(name = "password",value = "密码",required = true,dataType = "String"),
            @ApiImplicitParam(name = "token",value = "token",required = true,dataType = "String",paramType = "header"),
    })
//    返回值说明
    @ApiResponses(value = {
            @ApiResponse(code = 400,message = "xxx错误"),
            @ApiResponse(code = 300,message = "xxx错误")

    })
    public Client test1(String username, String password, @RequestHeader String token){
        return new Client();
    }

    @RequestMapping("/swagger/test2")
    @ApiOperation("查询年龄接口")
    @ApiImplicitParam(name = "token",value = "token",required = true,dataType = "int")
    public String test2(int age){
        return "OK";
    }
}

实体类:

@Data
@ApiModel("客户类")
public class Client {
    @ApiModelProperty(name = "cname",value = "客户名")
    private String cname;
    @ApiModelProperty(name = "money",value = "账户余额")
    private double money;
}

查看文档:http://localhost:8080/swagger-ui/index.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值