springmvc 传递对象数组参数 property path is neither an array nor a List nor a Map
Spring MVC 3: Property referenced in indexed property path is neither an array nor a List nor a Map
For example if you have a json object like:
{
"beans":[
{
"agreemendId":1,
"answerId":2
}
]
}
springmvc中的接收参数如下:
@ResponseBody
public Result update(@ModelAttribute Role dataList) {。。。}
其中,Role,Bean的定义:
public class Role{
List<Bean> beans;
public List<Bean> getBeans(){ return beans;}
public void setBeans(List<Bean> beans){this.beans=beans;}
}
public class Bean{
private Integer agreemendId;
private Integer answerId;
set....
get....
}
注意到,ajax中提交的参数beans与Role类中的属性beans必需一致。
JQuery will map your parameters like
beans[0][agreementId]:1
beans[0][answerId]:2
The problem is that Spring MVC is expecting a parameter format like
beans[0].agreementId:1
beans[0].answerId:2
In order to get that you can do it in 1 of two ways. You can do the quick and dirty way, which changes the way you're building your json object. Or, the other way is to extend the jQuery plugin to build parameters differently.
To change the javascript code was pretty simple and looked something like this
var answers = {};
answers['beans[' + index +'].agreementId'] = agreementId;
answers['beans[' + index +'].answerId'] = value;
$.ajax({
url:url,
data: answers ,
dataType:'json',
type:'post',
success:function(data){
console.log(data)
}
})
And for reference here are the pojos I was mapping to.
springmvc 传递对象数组参数 property path is neither an array nor a List nor a Map的更多相关文章
- SpringMVC接收对象数组参数进行封装
前台代码:注意.contentType : "application/json; charset=utf-8",必须要设置,只有这样SpringMVC才认识这个json数组参数 f ...
- Property referenced in indexed property path is neither an array nor a List nor a Map
记一次传参请求报错,没有解决 Invalid property 'distributeCars[0][ackStatus]' of bean class [com.api6.plate.prototy ...
- springMVC传递对象参数
初学java,由于项目紧急,来不及仔细的研究,在传递参数时就老老实实的一个一个的采用@RequestParam注解方式传递,最近认真看了一下,发现java也具有类似Asp.net Mvc传递对象做参数 ...
- springMvc接收ajax数组参数,以及jquery复选框选中、反选、全选、全不选
一.复选框选中.反选.全选.全不选 html代码: <input type='checkbox' name='menuCheckBox' value='10' >苹果 <input ...
- form表单传递对象数组
ajax传递数组.form表单提交对象数组 在JSP页面开发中,我们常常会用到form表单做数据提交,由于以前一直只是使用 form表单提交单个对象,只要表单文本域的name值和接收的对象的属性名一致 ...
- Vue在v-for中给css传递一个数组参数
需求就是将很多个数据,以进度条的形式展示在页面上,形成一个可视化. 接下来是html代码 <!DOCTYPE html> <html> <head> <tit ...
- JS传递对象数组为参数给后端,后端获取
前端JS代码: var conditons = []; var test1 = new Object(); test1.name="1"; test1.id="2&quo ...
- SQL Server 存储过程 数组参数 (How to pass an array into a SQL Server stored procedure)
Resource from StackOverflow 使用存储过程,如何传递数组参数? 1.分割解析字符串,太麻烦 2.添加Sql Server 自定义类型 sp_addtype 问题需求:需要向S ...
- 关于springMVC 传递 对象参数的问题
1.前端请求必须是 post 2.前端数据data必须做 json字符串处理 JSON.stringify(data) 3. contentType: 'application/json', 4.@ ...
随机推荐
- Deep Learning and the Triumph of Empiricism
Deep Learning and the Triumph of Empiricism By Zachary Chase Lipton, July 2015 Deep learning is now ...
- Scala中的Extractor
Scala中使用unapply方法可以实现三种extractor(另外使用unapplySeq也可以实现extractor) def unapply(object: S): Option[(T1, . ...
- [BEC][hujiang] Lesson04 Unit1:Working life ---Reading + Listening &Grammar & Speaking
4 1.1 Working life P10 Reading----The anonymous CV Exercise 3 What should be included in the CV ...
- 钣金的折弯成型工艺(Press Braking)
钣金的折弯成型:金属板材的弯曲和成型是在弯板机上进行的,将要成型的板材放置在弯板机上,用升降杠杆将制动片提起,工件滑动到适当的位置,然后将制动片降低到要成型的板材上,通过对弯板机上的弯曲杠杆施力而实现 ...
- dom4j 的小小测试
@Test public void gogo() throws IOException{ InputStream in = this.getClass().getClassLoader() .getR ...
- ARM7ldr指令与ldr伪指令
ldr伪指令的第二个操作数之前有个=,意思是第一个操作书 = 第二个操作数,相当明了 核心就在于对于用.word指令在.text段里另外定义一段内存,用ldr r0,[pc + x(可以算出.text ...
- poj 1611 The Suspects(简单并查集)
题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...
- My97 DatePicker使用之自定义事件
参考网站:http://www.my97.net/dp/demo/resource/2.5.asp 自定义事件 如果你需要做一些附加的操作,你也不必担心,日期控件自带的自定义事件可以满足你的需求.此外 ...
- C#中父窗口和子窗口之间实现控件互操作
很多人都苦恼于如何在子窗体中操作主窗体上的控件,或者在主窗体中操作子窗体上的控件.相比较而言,后面稍微简单一些,只要在主窗体中创建子窗体的时候,保留所创建子窗体对象即可. 下面重点介绍前一种,目前常见 ...
- 浅谈HTTP中Get、Post、Put与Delete的区别
Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...