swagger

1、依赖

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>

2、使用

@Configuration
@EnableSwagger2//开启swagger
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment){
        Profiles profiles = Profiles.of("dev");
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
//                .paths(PathSelectors.ant("/hello"))
                .build()
                .enable(flag);
    }

    public ApiInfo apiInfo(){
        Contact DEFAULT_CONTACT = new Contact("Yan", "Shi", "Heng");
        ApiInfo info = new ApiInfo(
                "Lao Yan",
                "Mr Yan",
                "1.0",
                "urn:tos",
                DEFAULT_CONTACT,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
        return info;
    }
}

多个组:创建多个docket

@ApiModel 实体类
@ApiModelProperty 实体类属性
@ApiOperation 请求方法

posted @ 2022-12-19 23:00  max_yan  阅读(23)  评论(0)    收藏  举报