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入门教程
  • 热门搜索
    咖啡能减肥吗 例假期间可以减肥吗 运动装搭配 五台山攻略 红烧日本豆腐 普洱茶能减肥吗 穿山甲怎么吃 小米机顶盒怎么安装 重生六零幸福攻略 专业减肥方法