前端发送请求相应格式,后端解析前端数据格式归纳
1
前端发送格式:
{memberId: “1365531544990523393”, productId: 12}
后端解析:
将字符串转成Json对象
@PostMapping("delCart")
public boolean delCart(@RequestBody String map) {
JSONObject mapJson=JSONObject.parseObject(map);
if(mapJson!=null) {
log.warn("delCart---前端发来的请求---"+mapJson.get("memberId")+"---"+mapJson.get("productId"));
return true;
}
return false;
}
2
前端发送格式
{
"memberId": "1",
"recipient": "jlf ",
"address": "内蒙古自治区巴彦淖尔市杨柳",
"tel": "222",
"goodsList": [{
"productId": 9,
"productNum": 1,
"productName": "小米11",
"imgurl": "https://ae01.alicdn.com/kf/U94ee4628aaa944f297157e846e546d2fH.jpg",
"totalPrice": 654,
"price": 654,
"srcList": ["https://ae01.alicdn.com/kf/U94ee4628aaa944f297157e846e546d2fH.jpg"]
}, {
"productId": 12,
"productNum": 1,
"productName": "赞赏",
"imgurl": "https://ae01.alicdn.com/kf/Uf4cb95ae1c594af5b2820481d62460782.jpg",
"totalPrice": 10,
"price": 10,
"srcList": ["https://ae01.alicdn.com/kf/Uf4cb95ae1c594af5b2820481d62460782.jpg"]
}],
"payment": 664,
"buyerMessage": "22"
}
后端解析
采用JSON转对象工具自动生成bean对象
https://www.bejson.com/json2javapojo/new/
/**
* Copyright 2021 bejson.com
*/
package com.bejson.pojo;
import java.util.List;
/**
* Auto-generated: 2021-03-05 13:57:33
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class JsonRootBean {
private String memberId;
private String recipient;
private String address;
private String tel;
private List<GoodsList> goodsList;
private int payment;
private String buyerMessage;
public void setMemberId(String memberId) {
this.memberId = memberId;
}
public String getMemberId() {
return memberId;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public String getRecipient() {
return recipient;
}
public void setAddress(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getTel() {
return tel;
}
public void setGoodsList(List<GoodsList> goodsList) {
this.goodsList = goodsList;
}
public List<GoodsList> getGoodsList() {
return goodsList;
}
public void setPayment(int payment) {
this.payment = payment;
}
public int getPayment() {
return payment;
}
public void setBuyerMessage(String buyerMessage) {
this.buyerMessage = buyerMessage;
}
public String getBuyerMessage() {
return buyerMessage;
}
}
/**
* Copyright 2021 bejson.com
*/
package com.bejson.pojo;
import java.util.List;
/**
* Auto-generated: 2021-03-05 13:57:33
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class GoodsList {
private int productId;
private int productNum;
private String productName;
private String imgurl;
private int totalPrice;
private int price;
private List<String> srcList;
public void setProductId(int productId) {
this.productId = productId;
}
public int getProductId() {
return productId;
}
public void setProductNum(int productNum) {
this.productNum = productNum;
}
public int getProductNum() {
return productNum;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductName() {
return productName;
}
public void setImgurl(String imgurl) {
this.imgurl = imgurl;
}
public String getImgurl() {
return imgurl;
}
public void setTotalPrice(int totalPrice) {
this.totalPrice = totalPrice;
}
public int getTotalPrice() {
return totalPrice;
}
public void setPrice(int price) {
this.price = price;
}
public int getPrice() {
return price;
}
public void setSrcList(List<String> srcList) {
this.srcList = srcList;
}
public List<String> getSrcList() {
return srcList;
}
}
直接完美解析
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗