SpringMVC 接收复杂对象

要发送的数据为:String topicId,String topicName,String summarize,List<ModuleParam> parentList

前端页面ajax请求数据,代码:

 1 exportData('${ctx}/report/compositeReport/export.do',{topicId:'${topicId}', topicName:'${topicName}', summarize:$("#summarizeContent").html(), 'parentList':$parentList});
 2 
 3 function exportData(url,params){
 4     common.showLoading('正在生成文件, 请稍后...');
 5        $.ajax({
 6            'url':url,
 7            'type':'post',
 8            'data':JSON.stringify(params),
 9            'dataType':'json',
10            'contentType':'application/json;charset=utf-8',
11            success:function(result){
12                common.hideLoading();
13                if (result.success) {
14                        var  filename= result.data;
15                        common.dialogEdit('导出报告', "${ctx}/report/compositeReport/download.do?fileName="+filename);
16                    } else {
17                        common.showMsg('导出失败!');
18                    }
19            },
20            error:function(res){
21                common.showMsg(res.responseText);
22            }
23        });
24 }

controller代码:

1     @RequestMapping("/compositeReport/export")
2     @ResponseBody
3     public JsonResult export(@RequestBody Map<String,Object> json, HttpServletRequest request, HttpServletResponse response){
4         JsonResult result = JsonResult.createWithFail();
5         List<ModuleParam> moduleList = JSONObject.parseArray(json.get("parentList").toString(), ModuleParam.class);
6         String topicName = json.get("topicName").toString();
7         String topicId = json.get("topicId").toString();
8         String summarize = json.get("summarize").toString();
9                 。。。。。。。

json参数的变量名可以随便写,这个list其实用json.get("parentList")的结果强转也可以得到,但是会报类型安全警告看着不爽,加个suppress注解也麻烦,就这样转换一下吧。

 

参考:4种方法让SpringMVC接收多个对象  http://blog.csdn.net/lutinghuan/article/details/46820023

转载于:https://www.cnblogs.com/GoQC/p/5541429.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值