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

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。