Springboot Swagger-ui 服务文档

1、简介

swagger是一款流行的API框架,用于生成服务文档,可视化、可调用、自定义规范,简化了开发过程,实时同步API文档的强大功能,相对于其他手写API文有极大优势

2、使用

  • 依赖 版本不同,自行选择
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.6.1</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.6.1</version>
</dependency>
  • 配置 1
@Configuration
@EnableSwagger2
public class Swagger {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .groupName("分组")
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.test.controller"))
        .paths(PathSelectors.any())
        .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
        .title("Spring boot Swagger-ui")
        .description("描述信息")
        .termsOfServiceUrl("http://www.baidu.com/")
        .version("1.0")
        .build();
    }
}
  • 配置 2
    @EnableSwagger2
    @Configuration
    public class Swagger {
        @Bean
        public Docket swaggerApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .groupName("/hello")
                    .genericModelSubstitutes(DeferredResult.class)
                    .useDefaultResponseMessages(false)
                    .forCodeGeneration(true)
                    .pathMapping("")// api测试请求地址,最终调用接口后会和paths拼接在一起
                    .select()
                    .paths(PathSelectors.regex("/.*"))// 过滤的接口
                    .build();
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值