代碼: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;@Beanpublic 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();} } ```
http://127.0.0.1:9091/swagger-ui.html#/
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态