当前位置: 首页 > news >正文

Springboot整合knife4j配置swagger教程-干货

开启swagger文档,直接上教程。

第一步:引入依赖

    <!--swagger 依赖--><dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>3.0.3</version></dependency>

第二步:添加配置文件

package com.test.empback.config;import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;/*** @author: 公众号:知识浅谈 个人微信:CYF2918CYF* Package:  com.test.empback.config* @date: 2023/9/3 15:40* @Description: swagger配置* @version: 1.0*/
@Configuration
@EnableKnife4j
public class Knife4jConfig {@Beanpublic Docket createRestApi() {return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage("com.test.empback<这个地方改成你的包名>")).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder().title("Springboot项目 后台服务API接口文档").description("使用 knife4j 搭建的后台服务API接口文档").contact(new Contact("你的姓名","你的网站","你的邮箱")).version("1.0.0").build();}
}

第三步:弄一个controller试试

@Api("公告相关控制器")
@RequestMapping("/")
public class TestController {@GetMapping("/test")public Result get(){return "test";}
}

然后运行项目:
打开网址 http://localhost:你设置的端口,没有设置默认为8080/api/doc.html

我的设置的8081,所以我就访问http://localhost:8081/api/doc.html

http://www.lryc.cn/news/152902.html

相关文章:

  • C++ 中的 Pimpl 惯用法
  • 【个人博客系统网站】统一处理 · 拦截器
  • 深入探索PHP编程:文件操作与输入/输出(I/O)
  • 基于jeecg-boot的flowable流程自定义业务驳回到发起人的一种处理方式
  • 【大数据知识】大数据平台和数据中台的定义、区别以及联系
  • 华为OD:IPv4地址转换成整数
  • 2023.9 - java - 浅拷贝
  • STM32f103入门(10)ADC模数转换器
  • 实训笔记8.28
  • 机器学习笔记之最优化理论与方法(五)凸优化问题(上)
  • 在Windows10上编译grpc工程,得到protoc.exe和grpc_cpp_plugin.exe
  • 一些测试知识
  • Socket交互的基本流程?
  • css 分割线中间带文字
  • 会不会激发对modern c++的新兴趣
  • Nginx服务器如何配合Java开发项目
  • 【LeetCode-中等题】994. 腐烂的橘子
  • K8s部署单机mysql
  • Midjourney学习(二)参数的基础
  • Ubuntu安装Protobuf,指定版本
  • 没有使用sniffer dongle在windows抓包蓝牙方法分享
  • 解决Debian系统通过cifs挂载smb后,中文目录乱码问题
  • springboot整合jquery实现前后端数据交互
  • TypeScript 中的类型检查实用函数
  • JavaScript中的事件委托(event delegation)
  • ubuntu OCR 脚本
  • Go死码消除
  • 基于改进莱维飞行和混沌映射的粒子群优化BP神经网络分类研究(Matlab代码实现)
  • 12. 自动化项目实战
  • Window11下载安装jdk8-jdk11与环境变量的配置