zoukankan      html  css  js  c++  java
  • 前台使用复杂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...
    	}
    
  • 相关阅读:
    C# Socket 入门2(转)
    C# Socket 入门1(转)
    StructLayout特性(转)
    [转载]U3d常规性能优化技巧
    Python语言系统学习(七)
    Python语言系统学习(五)
    python语言系统学习(六)
    python语言系统学习(四)
    白话经典算法-常见排序算法的实现与性能比较
    最快的内容查找算法-----暴雪的Hash算法
  • 原文地址:https://www.cnblogs.com/AngeLeyes/p/7999047.html
Copyright © 2011-2022 走看看