- 1-利用Springinit新建项目
- 2-pom文件导入fastjson包
- 3-测试代码
- 4- postman
- 5-网页打开
3-测试代码com.alibaba fastjson2.0.2
package com.wxlifeassistanttest.Controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.sql.SQLException;
@Controller
public class HelloController {
@RequestMapping(path="/test",method = RequestMethod.GET)
public String login_html(){
return "forward:test.html";
}
@RequestMapping(path = "/test", method = RequestMethod.POST)
@ResponseBody
public JSONObject Hello(@RequestBody(required = false) JSONObject test) throws SQLException {
System.out.println("接收到前端信号");
JSONObject json = new JSONObject();
if(test.get("msg").equals("1")){
json.put("msg","success");
}else {
json.put("msg","fail");
}
return json;
}
}
test.html放在static中
菜鸟教程(runoob.com)
我的第一个标题
我的第一个段落。
4- postman


![利用Postman发送json请求测试后端响应[2022/5/13] 利用Postman发送json请求测试后端响应[2022/5/13]](http://www.mshxw.com/aiimages/31/881807.png)
