本文主要是介绍Spring Boot使用Swagger和WireMock与前端并行开发,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- Spring Boot使用`Swagger`和`WireMock`与前端并行开发
- 1. `Swagger`
- 1.1 作用:根据代码自动生成文档
- 1.2 配置`pom.xml`
- 1.3 在启动类上添加注解
- 1.4 查看路径
- 1.5 效果展示
- 1.6 中文配置
- 2. `WireMock`
Spring Boot使用Swagger
和WireMock
与前端并行开发
1. Swagger
使用 Swagger
自动生成html
文档
-
1.1 作用:根据代码自动生成文档
-
1.2 配置
pom.xml
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version> </dependency><!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version> </dependency>
-
1.3 在启动类上添加注解
@EnableSwagger2
- 方法描述
在方法上添加注解配置@ApiOperation(value = "方法中文含义")
- 参数描述
参数是对象时,在对象的属性上添加@ApiModelProperty(value = "用户名")
,示例:
参数是非对象时,在参数名前加注解/** * @Project: tdt-security * @ClassName: UserVo * @Author: Mr.superbeyone * @Time: 2018-11-24 23:31 * @Description: User查询结果封装 **/public class UserVo {@ApiModelProperty(value = "用户名")private String username;@ApiModelProperty(value = "用户邮箱")private String email;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;} }
@ApiParam(value = "用户主键id")
,示例:@GetMapping("/{id:\\d+}") @JsonView(User.UserDetailView.class) public User query(@PathVariable(name = "id") @ApiParam(value = "用户主键id") String id) {System.out.println("查询user信息");User user = new User();user.setUsername("superbeyone");user.setPassword("password");return user; }
- 效果展示
2. WireMock
使用WireMock
快速伪造RESTful
服务
- 官网传送门
- 下载地址
- pom.xml
<!-- https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock -->
<dependency><groupId>com.github.tomakehurst</groupId><artifactId>wiremock</artifactId><version>2.19.0</version><type>pom</type><scope>test</scope>
</dependency>
- 启动
WireMock
服务
java -jar wiremock-standalone-2.19.0.jar
详细配置参见官方文档 传送门
github 项目源码地址
这篇关于Spring Boot使用Swagger和WireMock与前端并行开发的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!