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;
}
}
直接完美解析