微服务 教程
1085个小节阅读:196.6k
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
创建springboot项目
项目中 controller 中包含一个 Handler,用于测试项目,保证程序可以正确运行。
x
"/people") (
public class DemoController {
"/getPeople") (
public People getPeople(Long id, String name){
People peo = new People();
peo.setId(id);
peo.setName(name);
peo.setAddress("海淀");
return peo;
}
}
导入Spring-fox 依赖
在项目的pom.xml中导入Spring-fox依赖。选择版本2.9.2,所以导入的依赖也是这个版本。其中 springfox-swagger2 是核心内容的封装。springfox-swagger-ui 是对 swagger-ui 的封装。
xxxxxxxxxx
<dependency>
<groupId>io.springfox</ groupId>
<artifactId>springfox-swagger2</ artifactId>
<version>2.9.2</ version>
</dependency>
<dependency>
<groupId>io.springfox</ groupId>
<artifactId>springfox-swagger-ui</ artifactId>
<version>2.9.2</version>
</dependency>
添加注解
在 SpringBoot 的启动类中添加@EnableSwagger2 注解。添加此注解后表示对当前项目中全部控制器进行扫描,应用Swagger2。
xxxxxxxxxx
public class MyApp {
public static void main(String [] args){
SpringApplication.run(MyApp.class,args);
}
}
访问 swagger-ui
启动项目后在浏览器中输入http://ip:port/swagger-ui.html即可以访问到 swagger-ui 页面,在页面中可以可视化的进行操作项目中所有接口。
实时效果反馈
1.在springboot项目中使用Springfox需要引入的依赖有
A springfox-swagger2
B springfox-swagger-ui
C springfox-boot-starter
D 以上都对
答案
1=>C