spring boot + swagger2集成api接口文档
Swagger是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。文件的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步。Swagger 让部署管理和使用功能强大的API从未如此简单。
pox.xml文件配置:
<!--swagger2 start--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency> <!--swagger2 end-->
spring boot 配置:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
maven项目结构:
在代码的控制类中加入相关的注解
说明:
其中@ApiOperation和@ApiParam为添加的API相关注解,各参数说明如下:
@ApiOperation(value = “接口说明”, httpMethod = “接口请求方式”, response = “接口返回参数类型”, notes = “接口发布说明”);其他参数可参考源码;
@ApiParam(required = “是否必须参数”, name = “参数名称”, value = “参数具体描述”)
最常用的5个注解
@Api:修饰整个类,描述Controller的作用 @ApiOperation:描述一个类的一个方法,或者说一个接口 @ApiParam:单个参数描述 @ApiModel:用对象来接收参数 @ApiProperty:用对象接收参数时,描述对象的一个字段
其它若干
@ApiResponse:HTTP响应其中1个描述 @ApiResponses:HTTP响应整体描述 @ApiIgnore:使用该注解忽略这个API @ApiClass @ApiError @ApiErrors @ApiParamImplicit @ApiParamsImplicit
效果图:
swagger2 比 swagger 不用手动添加swagger的页面
猜你喜欢
- spring boot集成swagger knife4j极简入门实例
- SpringBoot整合Swagger基本实现
- SpringBoot入门整合开发java Web项目实例
- Springboot+thymeleaf对员工的增删改查操作 带分页功能
- Springboot+Mybatis+maven+layui开发简单的学习实例
- springboot2.x+mybatis-plus+jsp+jpa简单增删改查实例(仅供学习)
- spring boot+mybatis+mysql基础配置实现部门数据增加查询更新功能
- Spring Boot1.3.6 Angularjs1.4.0 Mongodb2.3.6 CRUD汽车搜索及增加修改程式
- Spring Boot整合Hazelcast Caching的简单入门实例
- Spring Boot入门实现HelloWorld简单实例
- spring boot+springdata jpa的项目整合demo例子
- mac下spring boot基础增删改查项目实例
- /
- /Swagger
- /Swagger/.classpath
- /Swagger/.project
- /Swagger/.settings
- /Swagger/.settings/.jsdtscope
- /Swagger/.settings/org.eclipse.core.resources.prefs
- /Swagger/.settings/org.eclipse.jdt.core.prefs
- /Swagger/.settings/org.eclipse.m2e.core.prefs
- /Swagger/.settings/org.eclipse.wst.common.component
- /Swagger/.settings/org.eclipse.wst.common.project.facet.core.xml
- /Swagger/src
- /Swagger/src/main
- /Swagger/src/main/java
- /Swagger/src/main
- /Swagger

- 证 Spring Boot创建自定义Banner.txt实例
- 证 Spring Boot配置@Profile注解加载不同环境的配置文件实例
- 证 Spring Boot Actuator 2.3.4.RELEASE新版本实现自定义端点信息的配置实例
- 原证 spring AOP 过滤器 拦截器 执行顺序示例
- 证 spring boot使用不指定Maven parent pom来创建可执行的spring boot项目
- 证 Spring Boot整合thymeleaf做为显示层的hello world实例
- 证 Spring Boot整合SpringFox Swagger2实现REST API增删改查项目实例
- 证 Spring Boot演示@ConfigurationProperties标注实现自定义配置属性的实例
- 证 Spring Boot整合Ehcache的简单入门实例
- 原 SpringBoot入门整合开发java Web项目实例
- 证 Springboot+thymeleaf对员工的增删改查操作 带分页功能
- 证 Spring Boot整合Freemarker实现文件上传项目实例
