• 1、添加依赖
  • <!-- swagger -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.2.2</version>
    </dependency>
    

  • 2、创建Bean类(配置类)
  • package mavennexusceshi.demo.config;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    import springfox.documentation.service.ApiInfo;
    
    @Configuration
    @EnableSwagger2
    public class Swagger2 {
        @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("your project name"))//"com.dddddddddd.dd.apy"
                    .paths(PathSelectors.any())
                    .build();
        }
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("your company")
                    .description("company API")
                    .termsOfServiceUrl("http://www."gongsi".com/--请求接口的url")
                    .contact("接口的负责人")
                    .version("1.1.1")
                    .build();
        }
    }
    

  • 3、springboot-------swagger2使用springboot-------swagger2使用springboot-------swagger2使用
  • 最后为效果图

相关文章:

  • 2021-08-04
  • 2021-10-29
  • 2021-05-25
  • 2021-07-01
  • 2021-08-30
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-16
  • 2021-08-15
  • 2022-12-23
  • 2021-12-03
  • 2021-09-09
  • 2021-05-24
  • 2022-01-13
相关资源
相似解决方案