22.案例实战:把springboot的接口,自动生成接口文档
代码:https://github.com/NIGHTFIGHTING/spring_boot_learning/tree/master/21-22/agan-boot/agan-boot-swagger
Swagger UI 呈现出来的是一份可交互式的 API 文档,我们可以直接在文档页面尝试 API 的调用,省去了准备复杂的调用参数的过程。
增加一个swagger配置类 ``` @Configuration @EnableSwagger2 public class SwaggerConfig { @Value(value = "${spring.swagger2.enabled}") private Boolean swaggerEnabled; @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .enable(swaggerEnabled) .select() .apis(RequestHandlerSelectors.basePackage("com.agan.boot")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("接口文档") .description("阿甘讲解 Spring Boot") .termsOfServiceUrl("https://study.163.com/provider/1016671292/index.htm") .version("1.0") .build(); } } ```