前端发送请求相应格式,后端解析前端数据格式归纳

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;
     }

}

在这里插入图片描述
直接完美解析

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值