对于后端来说,不用去考虑前端的布局,只考虑后端数据的正确性,那么在后端测试返回的Json数据的正确性就离不开Postman工具。
Postman 是一款功能强大的网页调试与发送网页 HTTP 请求的工具。Postman 能够发送 任何类型的 HTTP 请求(GET, HEAD, POST,PUT..),附带任何数量的参数和 HTTP headers。 支持不同的认证机制(basic, digest,OAuth),接收到的响应语法高亮(HTML,JSON 或 XML)。 Postman 既可以以 Chrome 浏览器插件的形式存在,也可以是独立的应用程序存在.
Postman 下载安装
官方下载地址:https://www.getpostman.com/apps。
Postman 适用于不同的操作系统,Postman Mac、Windows X32、Windows X64、Linux 系统,还支持 postman 浏览器扩展程序、postman chrome 应用程序等。根据自己的情况下, 下载安装对应环境的版本即可。
下载后,按提示进行默认安装即可,这里就省略了。安装完成后,首页界面以及基础功 能如图所示。
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.postman</groupId>
<artifactId>postman</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<!-- 声明项目配置依赖编码格式为 utf-8 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<fastjson.version>1.2.24</fastjson.version>
</properties>
<dependencies>
<!--SpringBoot热部署配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
spring.devtools.restart.enabled=true
spring.devtools.restart.additional-paths=src/main/java
spring.devtools.restart.exclude=WEB-INF/**
spring.freemarker.cache=false
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
aaaaaaaaa
</body>
</html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
hahhahahah
<br>
asdas
</body>
</html>
package com.tszr.postman.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloDemo {
@RequestMapping("/index")
public String index() {
return "login";
}
@RequestMapping("/main")
public String home() {
return "home!";
}
}
package com.tszr.postman.controller;
import com.tszt.postman.util.JsonResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class PostmanController {
@PostMapping("login")
public JsonResult<String> login(String username, String password) {
JsonResult<String> result = new JsonResult<String>();
result.setData(username);
result.setCode("0");
result.setMsg("操作成功!");
return result;
}
}
package com.tszr.postman;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}