Swagger2

作者: 蓝色Hippie | 来源:发表于2020-06-26 17:59 被阅读0次

一、引入jar包

<dependency>

    <groupId>io.springfox</groupId>

    <artifactId>springfox-swagger2</artifactId>

<version>2.4.0</version>

</dependency>

<dependency>

    <groupId>io.springfox</groupId>

    <artifactId>springfox-swagger-ui</artifactId>

    <version>2.4.0</version>

</dependency>

<dependency>

    <groupId>com.github.xiaoymin</groupId>

    <artifactId>swagger-bootstrap-ui</artifactId>

    <version>1.6</version>

</dependency

二、配置

//让spring知道是配置类

@Configuration

//开启swagger

@EnableSwagger2

public class Swagger2 {

//文档地址

//http://localhost:8088/doc.html

//http://localhost:8088/项目名/swagger-ui.html

    @Bean

    public Docket createtRestApi() {

            return new Docket(DocumentationType.SWAGGER_2)//指定api类型为swagger2

                .apiInfo(apiinfo())//用于定义api文档汇总信息

                .select().apis(RequestHandlerSelectors.basePackage("com.imooc.controller"))//指定controller包

                .paths(PathSelectors.any())//所有controller都生成文档

                .build();

    }

    private ApiInfo apiinfo() {

        return new ApiInfoBuilder()

            .title("吃货小平台")

            .version("1.0.0")

            .description("本平台致力于服务吃货们,为吃货们提供一系列顶尖的推荐。")

            .contact(new Contact("Janos","http://www.baidu.com","111@163.com"))

            .build();

    }

}

三、使用

controller中设置文档接口说明 实体类中也可以说明 文档api

相关文章

网友评论

      本文标题:Swagger2

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