
接口文档是前后端协作的桥梁。手写文档费时且容易和代码不一致Knife4j 可以自动从注解生成接口文档提供在线调试功能。一、为什么选 Knife4j对比Knife4jSwagger UI手写文档UI 美观度⭐⭐⭐⭐⭐ 中文友好⭐⭐⭐ 英文原生⭐⭐⭐在线调试✅ 支持✅ 支持❌代码侵入低注解低注解无但费时维护成本自动同步自动同步⭐⭐⭐ 极高二、集成 Knife4j1. 引入依赖dependencygroupIdcom.github.xiaoymin/groupIdartifactIdknife4j-spring-boot-starter/artifactIdversion3.0.3/version/dependency2. 配置spring:mvc:pathmatch:matching-strategy:ant_path_matcherknife4j:enable:truesetting:language:zh-CNenable-swagger-models:trueenable-document-manage:trueswagger-model-order:13. 配置类ConfigurationEnableKnife4jpublicclassKnife4jConfig{BeanpublicDocketdefaultApi(){returnnewDocket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage(com.zhang)).paths(PathSelectors.any()).build();}privateApiInfoapiInfo(){returnnewApiInfoBuilder().title(秒杀系统接口文档).description(电商秒杀系统 RESTful API).version(V1.0).contact(newContact(张政,,)).build();}}访问http://localhost:9090/doc.html即可看到接口文档页面。 觉得有用的话点赞 关注【张老师技术栈】吧