美文网首页
springboot集成swagger-ui

springboot集成swagger-ui

作者: 龙泉诗 | 来源:发表于2019-06-15 19:09 被阅读0次

前言

记录软件开发点滴,积累知识和经验(第一篇)

要做什么?

目标:完成springboot集成swagger的功能。

怎样去做?

  • 引入对应的jar(pom.xml)
 <!--  swagger-ui    -->
      <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>
  • 配置swagger(swagger2Config.java)
@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.wyl.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("springboot利用swagger构建api文档")
                .description("简单优雅的restfun风格,http://blog.csdn.net/saytime")
                .termsOfServiceUrl("http://blog.csdn.net/saytime")
                .version("1.0")
                .build();
    }
}

  • swagger的相关使用
    @Api(用在类中标明这个类的作用)
    @ApiOperation(用在方法中,标明这个方法的作用)
    @ApiImplicitParams(用在有参数的方法中,标明参数的作用)

结果怎么样? 在这里插入图

相关文章

网友评论

      本文标题:springboot集成swagger-ui

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