Ajax传递数组对象

Ajax传递数组对象,第1张

Ajax传递数组对象 Ajax传递数组对象

一、JS部分写法
1、JSON.stringify(submitMainComponent.billSubmit) 转json
2、contentType: ‘application/json’ 类型用json

$.ajax({
    url : context + '/submit/save',
    data:JSON.stringify(submitMainComponent.billSubmit),
    type : 'post',
    contentType: 'application/json',
    cache : false,
    success:function(ret){
        if (ret) {
            if (ret.retCode == GLOBAL_INFO.SYS_SUCCESS) {
                test.ret = ret;
                if (ret.retObj) {
 
                }
            }
        }
    }
});

二、java 部分写法
1、参数写法 @RequestBody List> list 如果js中定义的参数和后台定义的bean一样,可以将map换成bean

@RequestMapping(value = "save")
@ResponseBody
public HandlerResult saveBill(@RequestBody List> list,
                              HttpServletRequest request)
{
    HandlerResult result = HandlerResult.newInstance();
    try
    {
        UserInfoBean userInfo = SessionUserUtils.gainUserFromSession(request);
        System.out.println(list);
 
        Map params = new HashMap();
        params.put("orgNum",userInfo.getOrg_num());
        Map goodsInfo = this.procureSubmitService.goodsInfo(params);
        result.setRetObj(goodsInfo);
        result.setRetCode(IResultCode.SYS_SUCCESS);
        result.setSysCode(SystemCodeConstants.QUERY_INFO_SUCCEED);
    }
    catch (Exception e)
    {
        e.printStackTrace();
        result.setRetCode(IResultCode.SYS_FAILED);
        result.setSysCode(SystemCodeConstants.QUERY_INFO_FAILED);
        result.setResMsg("内部异常!");
    }
    return result;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5482217.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存