Swagger配置

可以在项目中创建SwaggerConfig,进行配置文档内容。

配置基本信息

Docket:摘要对象,通过对象配置描述文件的信息。

apiInfo:设置描述文件中info。参数类型ApiInfo

select():返回ApiSelectorBuilder对象,通过对象调用build()可以创建Docket对象

ApiInfoBuilder:ApiInfo构建器。

@Configuration
public class SwaggerConfig {
    @Bean
    public Docket getDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(swaggerDemoApiInfo())
                .select()
                .build();
    }
    private ApiInfo swaggerDemoApiInfo(){
        return new ApiInfoBuilder()
                .contact(new Contact("北京尚学堂", "http://www.bjsxt.com", "xxx@163.com"))
                //文档标题
                .title("这里是Swagger的标题")
                //文档描述
                .description("这里是Swagger的描述")
                //文档版本
                .version("1.0.0")
                .build();
    }
}

  

 

 

 

设置扫描的包

可以通过apis()方法设置哪个包中内容被扫描

@Bean
public Docket getDocket() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(getApiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.bjsxt.controller"))
            .build();
}

  

自定义注解设置不需要生成接口文档的方法

1.1 自定义注解

注解名称随意。

@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface NotIncludeSwagger {
}

posted @ 2021-01-29 11:56  巧克力曲奇  阅读(115)  评论(0编辑  收藏  举报