柳州网站建设柳州,广州技术支持 奇亿网站建设,wordpress文章更新,网站开发相关专业1.Knife4j概述 Knife4j是一款基于Swagger UI的增强插件#xff0c;它可以为Spring Boot项目生成美观且易于使用的API文档界面。它是Swagger UI的增强版#xff0c;提供了更多的功能和定制选项#xff0c;使API文档更加易读和易于理解。
2.Knife4j使用
Knife4j 集Swagger2…1.Knife4j概述 Knife4j是一款基于Swagger UI的增强插件它可以为Spring Boot项目生成美观且易于使用的API文档界面。它是Swagger UI的增强版提供了更多的功能和定制选项使API文档更加易读和易于理解。
2.Knife4j使用
Knife4j · 集Swagger2及OpenAPI3为一体的增强解决方案. | Knife4jhttps://doc.xiaominfo.com/
2.1 导入依赖
dependencygroupIdcom.github.xiaoymin/groupIdartifactIdknife4j-openapi2-spring-boot-starter/artifactIdversion4.0.0/version
/dependency
2.2 配置配置类
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;/*** 配置类*/
Configuration
Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {/*** 通过knife4j生成接口文档*/Beanpublic Docket docket() {ApiInfo apiInfo new ApiInfoBuilder().title(外卖项目接口文档).version(2.0).description(外卖项目接口文档).build();Docket docket new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo).select().apis(RequestHandlerSelectors.basePackage(com.sky.controller)).paths(PathSelectors.any()).build();return docket;}/*** 设置静态资源映射*/protected void addResourceHandlers(ResourceHandlerRegistry registry) {log.debug(开始设置静态资源映射);registry.addResourceHandler(/doc.html).addResourceLocations(classpath:/META-INF/resources/);registry.addResourceHandler(/webjars/**).addResourceLocations(classpath:/META-INF/resources/webjars/);}
}