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...
    	}
    
  • 相关阅读:
    选择排序——Java实现
    冒泡排序——Python实现
    基数排序——Java实现
    Sqoop迁移Hadoop与RDBMS间的数据
    Hive Join
    Hadoop 完全分布式部署(三节点)
    springboot自定义异常处理
    linux下安装redis
    windows 下tomcat重启脚本
    解决rabbin首次请求慢的问题
  • 原文地址:https://www.cnblogs.com/AngeLeyes/p/7999047.html
Copyright © 2011-2022 走看看