swagger2

作者: xiezw96 | 来源:发表于2018-10-09 15:57 被阅读0次

第一步,添加依赖

<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>

第二步,swagger2的配置文件

@Configuration
@EnableSwagger2
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("controller路径"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("某公司某项目接口文档")
                .description("项目详情请访问:项目详情访问地址")
                .termsOfServiceUrl("项目详情访问地址")
                .contact("某程序员")
                .version("1.0")
                .build();
    }

}

第三步,在controller中添加@api或@ApiOperation等注释,最后就可以访问下面链接测试接口

http://localhost:8080/swagger-ui.html

相关文章

网友评论

      本文标题:swagger2

      本文链接:https://www.haomeiwen.com/subject/yvxyaftx.html