前台使用复杂json

前台使用复杂json,后台直接封装到对象

当我们需要一次向后台传入多个数据和一个list对象的时候,显然用fromb表单是很不方便的.比如要传入一下的数据

//一个list
        var customerArray = new Array();
        customerArray.push({id: 123, foodid: "字符串可以", merchantid: 3423});
        customerArray.push({id: 456, foodid: 234, merchantid: 554});
        
        
        //list和几个其他的对象
        exportData('/rest/FoodGroup/insertFoodGroup',{topicId:"蟑螂恶霸", topicName:"车轮滚滚", summarize:"蜻蜓队长", 'parentList':customerArray});
        
        
        
       function exportData(url,params){
           $.ajax({
               'url':url,
               'type':'post',
               'data':JSON.stringify(params),
               'dataType':'json',
               'contentType':'application/json;charset=utf-8',
               success:function(result){
                   
               },
               error:function(res){
                   
               }
           });
    } 
        

@Controller接收

@RequestMapping("/insertFoodGroup")
    @ResponseBody
     public String insertFoodGroup(@RequestBody Map<String,Object> json )
     {
        //先保存一份菜品.返回菜品id        
        //在保存分组和当前分组的菜品
        Object object = json.get("parentList");//拿到list对象
       //(这里的JSONArray用的是阿里的fastjson)
        List<TestBean> s=   new ArrayList<TestBean>(JSONArray.parseArray( JSON.toJSONString(object),TestBean.class));
                
        
        return  null;
     }
    

testBean

public class TestBean {
    private Integer id;
    private String foodid;
    private String merchantid;
  //getset...
    }

转载于:https://www.cnblogs.com/AngeLeyes/p/7999047.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值