当前位置:网站首页>Swagger3的使用
Swagger3的使用
2022-07-19 05:22:00 【谁是黄黄】
本篇涉及到的swagger注解(速记)
@EnableSwagger2 开启swagger
@EnableOpenApi 开启swagger的Api功能
@EnableWebMvc 是为了解决swagger和springmvc整合之后总是出现空指针异常的问题,要有springBoot web依赖哦
Swagger
根据当前的服务端接口,自动的生成接口文档,这个所谓的接口文档,实际上就是一个网站。
- 数据接口
- 网页 UI
一项目搭建
创建一个SpringBoot项目,加入依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
二.配置启动类
package com.huang.springboot9;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
/*开启swagger*/
@EnableSwagger2
@EnableOpenApi
/*EnableMVC,是为了解决swagger和springmvc整合之后总是出现空指针异常的问题,要有springBoot web依赖哦*/
@EnableWebMvc
public class SpringBoot9Application {
public static void main(String[] args) {
SpringApplication.run(SpringBoot9Application.class, args);
}
}
三.写一个简单的controller
package com.huang.springboot9.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "hello";
}
}
四.登录swagger网站;http://localhost:8080/swagger-ui/index.html
注意:
1.swagger2和swagger3的网站以及使用方法是不同的
2.你配置好注解后,运行springBoot后swagger的注解会自动为你配置好swagger
边栏推荐
- Dark horse programmer timer
- Gocore-v2 framework -gocore Introduction to yaml configuration file
- Solr搜索引擎 — SolrCloud安装和集群配置
- tensorflow tf.where使用方法,大于某个值为1,小于为0
- Lombok cooperates with logback to realize the simplest log output
- ModuleNotFoundError: No module named 'gflags'
- Pytorch:visdom介紹
- 分布式唯一ID
- Single arm routing and VRRP
- 今天学习定位
猜你喜欢
About querying basic resource information and viewing key data
Variable influence notes from UCB CS 285 Sergey Levine
搜索框的简易设置方式
gocore-v2框架-gocore.yaml配置文件介绍
Gocore-v2 framework - quick start
Scala case (companion object)
Kubernetes命令行管理工具 — Kubectl
gocore-v2框架发布-集成脚手架能力
Paper notes: neural baby talk
论文笔记:Self-critical Sequence Training for Image Captioning
随机推荐
Nat overview
LVM and disk quotas
Kubernetes terminal management tool - kubebox
Alibaba cloud micro message queue mqtt
下拉框三角的简易设置
Lambda usage
Introduction to dark horse programmer reflection
论文笔记:Look Back and Predict Forward in Image Captioning# Look Back and Predict Forward in Image Capti
js 使元素获取或失去焦点
Pytorch: Introduction à visdom
分布式唯一ID
论文笔记:Self-critical Sequence Training for Image Captioning
ModuleNotFoundError: No module named 'gflags'
ModuleNotFoundError: No module named 'gflags'
[report] TF fast RCNN runs its own training data could not broadcast input array from shape (4) into shape (0)
关于正向代理和反向代理的理解
浮动效果与特点
Insert cross column pictures under the title of the home page of latex IEEE paper, and solve the footnote problem
ModuleNotFoundError: No module named 'cv2'
[resource record] the relationship between manifold learning and PCA