zoukankan      html  css  js  c++  java
  • Spring Boot 配置 Swagger2

    Spring Boot 配置 Swagger2

    pom.xml

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

    SwaggerConfig.java

    @Configuration
    @EnableSwagger2
    public class Swagger2Config {
        @Bean
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                    .paths(PathSelectors.any())
                    .build();
        }
        public ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("Swagger")
                    .description("Rest API接口")
                    .version("0.1")
                    .build();
        }
    }
    

    HelloController.java

    @RestController
    @RequestMapping("hello")
    @Api(tags = "Hello接口")
    public class HelloController {
        @ApiOperation("首页")
        @GetMapping("")
        public List<String> index(){
            List<String> list=new ArrayList<>();
            list.add("米开朗基罗");
            list.add("拉斐尔");
            list.add("达芬奇");
            return list;
        }
        @ApiOperation("日期")
        @GetMapping("date")
        public Date date(){
            return new Date();
        }
    }
    
    

    注意

    使用fastjson时不要排除掉spring-boot-starter-json

  • 相关阅读:
    hdu4273Rescue(三维凸包重心)
    hdu4449Building Design(三维凸包+平面旋转)
    hdu3847Trash Removal(凸包)
    CodeForces 166B (凸包)
    机器学习文章导航
    梯度下降法深入
    插值法
    离散系统频域分析
    离散系统时域分析
    连续系统频域分析
  • 原文地址:https://www.cnblogs.com/yanzhen/p/12724953.html
Copyright © 2011-2022 走看看