接收 ajax POST 方式传入的参数

----前台---

var list = new Array();
        var params = {
            gencodeid : "test001",
            value : "01",
            name : "测试",
            type : "1100"
        };
        var params2 = {
            gencodeid : "test002",
            value : "02",
            name : "测试2",
            type : "1102"
        };
        list.push(params);
        list.push(params2);
        var ajaxSetting = {
            url : "../xxx/yyy",
            timeout : 60000,
            type : "POST",
            contentType : "application/json",
            dataType : "json",
            cache : false,
            async : false,
            data : JSON.stringify(list),
            success : function(resultValue) {
                if ($isFunction(p_callback)) {
                    p_callback(resultValue);
                }
            },
            error : function(request, status, error) {
                if ($isFunction(p_callback)) {
                    if (error == null) {
                        error = new Error(request.responseText);
                    }
                    var resultValue = {
                        successful : false,
                        error : error
                    };
                    p_callback(resultValue);
                }
            }
        };
        $.ajax(ajaxSetting)

---后台---

    /**
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/test4", method = RequestMethod.POST)
    public @ResponseBody
    Object test4(HttpServletRequest request,@RequestBody List<Map> list) throws Exception {
        for (Map map : list) {
            Set<String> set = map.keySet();
            for (String key : set) {
                System.out.println(key+":"+map.get(key));
            }
        }
        return null;
    }

 

posted on 2015-02-11 09:36  天凉好个球  阅读(923)  评论(0编辑  收藏  举报

导航