Spring Boot 2.X整合Swagger2

 时间:2026-04-25 14:03:42

1、在pom.xml中添加swagger2的坐标

Spring Boot 2.X整合Swagger2

2、在pom.xml中添加swagger-ui的坐标

Spring Boot 2.X整合Swagger2

3、新建一个Swagger2的配置类

加注解

@EnableSwagger2@Configuration

Spring Boot 2.X整合Swagger2

4、配置Swagger2

Spring Boot 2.X整合Swagger2

5、在Controller层添加API注解

@Api("用户接口")

@ApiOperation("获取所有用户")

Spring Boot 2.X整合Swagger2

6、启动项目,在浏览器输入网址

http://localhost/swagger-ui.html

Spring Boot 2.X整合Swagger2

7、点击try it out!进行测试

我这里写了一个查询所有用户的列子

Spring Boot 2.X整合Swagger2

Spring Boot 2.X整合Swagger2

  • spring boot整合freemarker模板引擎框架
  • spring boot整合ehcache缓存框架
  • springboot集成swagger2访问路径404
  • spring boot全局异常处理
  • Spring Boot入门教程
  • 热门搜索
    计数单位是什么 大暑是什么意思 hdmi是什么意思 怕冷是什么原因怎么调理 梦见马是什么意思 什么时候取环最合适 红红的太阳像什么 between是什么意思 3月14日是什么星座 信用卡最低还款额是什么意思