springbootweb集成swagger

server/2024/9/22 23:07:26/

可以选择集成原生swagger,我这里选择的是在swagger之上又封装了一层的knife4j。比原生swagger更好用点,可以看接口文档,测试接口

引入依赖

 <dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>3.0.2</version></dependency>

编写配置类


```java
package com.itheima.mp.config;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;/*** 配置类,注册web层相关组件*/
@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {/*** 通过knife4j生成接口文档** @return*/@Beanpublic Docket docket() {ApiInfo apiInfo = new ApiInfoBuilder().title("swagger文档").version("2.0").description("这是我的文档").build();Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo).select().apis(RequestHandlerSelectors.basePackage("com.itheima.mp")).paths(PathSelectors.any()).build();return docket;}/*** 设置静态资源映射** @param registry*/protected void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");}
}
## controller层和实体类上加注解
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/1bd4feab19b3416bbbd6282782ce020a.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/5a8115016885470c93f0fef839a0badf.png)## 访问swagger文档地址
项目启动地址/doc.html
例如 127.0.0.1:9090/doc.html
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/2bcf078ed6bd40a6b3a1cd3a3456d96f.png)

http://www.ppmy.cn/server/120510.html

相关文章

深度学习03-神经网络01-什么是神经网络?

神经网络的基本概念 人工神经网络&#xff08;Artificial Neural Network&#xff0c;ANN&#xff09;&#xff1a; 是一种模仿生物神经网络的计算模型。由多个神经元&#xff08;或称为节点&#xff09;组成&#xff0c;这些节点通过不同的连接来传递信息。 每个神经元可以接…

线阵相机的参数选型计算

一、要求 如果测量物体的宽度为1800mm,精度1毫米、运动速度25000mm/s。 1. 相机分辨率的确定 幅宽与像素的关系&#xff1a;客户要求的幅宽是1800毫米&#xff0c;精度是1毫米。理论上&#xff0c;如果每个像素对应1毫米&#xff0c;那么相机至少需要1800个像素来覆盖整个幅…

【AI学习笔记】初学机器学习西瓜书概要记录(二)常用的机器学习方法篇

初学机器学习西瓜书的概要记录&#xff08;一&#xff09;机器学习基础知识篇(已完结) 初学机器学习西瓜书的概要记录&#xff08;二&#xff09;常用的机器学习方法篇(持续更新) 初学机器学习西瓜书的概要记录&#xff08;三&#xff09;进阶知识篇(待更) 文字公式撰写不易&am…

研究生如何利用 ChatGPT 帮助开展日常科研工作?

ChatGPT科研 一、 如何精读论文“三步提问法”1.为什么要做这个研究&#xff1f;这个研究是否值得我们做&#xff1f;2.他们怎么做这个研究3.他们发现了什么&#xff1f; 二、如何利用ChatGPT快速精读论文&#xff1f;首先&#xff0c;“三步走之第一步”--为什么要做这个研究&…

uni-app生命周期

目录 一、页面生命周期 1、onLoad 【常用】 2、onShow【常用】 3、onReady【常用】 4、onHide【常用】 5、onPullDownRefresh【常用】 6、onReachBottom【常用】 二、应用生命周期 1、onLaunch【常用】 2、onShow【常用】 3、onHide【常用】 三、组件生命周期 1、…

Spring Service中的@Service注解的使用

Service注解是Spring框架中用于标识业务逻辑层&#xff08;Service层&#xff09;的注解。它是Spring组件扫描机制的一部分&#xff0c;表明这个类包含业务逻辑&#xff0c;并且应该由Spring容器管理为一个Spring Bean。它与Component类似&#xff0c;都是标识一个类为Spring管…

安卓沉浸式状态栏遇到的问题

1.顶部状态栏黑条问题 解决方案①&#xff1a;   在Activuty的onCreate方法中设置如下代码。 WindowManager.LayoutParams lp getWindow().getAttributes();if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {lp.layoutInDisplayCutoutMode WindowManager.LayoutPar…

IPsec-VPN中文解释

一 IPsec-VPN 实操 (点到点) 网络括谱图 IPSec-VPN 配置思路 1 配置IP地址 FWA:IP地址的配置 [FW1000-A]interface GigabitEthernet 1/0/0 [FW1000-A-GigabitEthernet1/0/0]ip address 10.1.1.1 24 //配置IP地址 [FW1000-A]interface GigabitEthernet 1/0/2 [FW10…