springboot-swagger配置

1.添加maven依赖

       

            io.springfox

            springfox-swagger2

            2.9.2

       

       

            io.springfox

            springfox-swagger-ui

            2.9.2

       

2.添加配置类

@Configuration

public class Swagger2 {

    @Bean

    public Docket createRestApi() {

        return new Docket(DocumentationType.SWAGGER_2)

                .apiInfo(apiInfo())

                .select()

                .apis(RequestHandlerSelectors.basePackage("com.demo.ikun.controller"))

                .paths(PathSelectors.any())

                .build();

    }

    private ApiInfo apiInfo() {

        return new ApiInfoBuilder()

                .title("配置管理子系统api文档")

                .description("API 描述")

                .version("1.0")

                .build();

    }

}

3.添加注解

1)主类

@SpringBootApplication
@EnableSwagger2
public class TimingApplication {
    public static void main(String[] args) {
        SpringApplication.run(TimingApplication.class, args);
    }
}

2.controller

@Api(tags = "暮影微凉接口")
@RestController
@RequestMapping("/twilight")
public class TwilightController {
    @ApiOperation(value = "得飞",notes = "注意事项:白费")
    @GetMapping("/getHer")
    public String getFei(){
        return "云";
    }
}

 

 

你可能感兴趣的:(java常用,java)