Spring MVC 3: Property referenced in indexed property path is neither an array nor a List nor a Map

 
JQuery's $.ajax does an excellent job mapping a json object to parameters, but when you start getting into more complex objects Spring MVC doesn't know how to interpret it sometimes.

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)

}

})

 
To modify the jquery plugin I would suggest taking a look here.

And for reference here are the pojos I was mapping to.

springmvc 传递对象数组参数 property path is neither an array nor a List nor a Map的更多相关文章

  1. SpringMVC接收对象数组参数进行封装

    前台代码:注意.contentType : "application/json; charset=utf-8",必须要设置,只有这样SpringMVC才认识这个json数组参数 f ...

  2. 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 ...

  3. springMVC传递对象参数

    初学java,由于项目紧急,来不及仔细的研究,在传递参数时就老老实实的一个一个的采用@RequestParam注解方式传递,最近认真看了一下,发现java也具有类似Asp.net Mvc传递对象做参数 ...

  4. springMvc接收ajax数组参数,以及jquery复选框选中、反选、全选、全不选

    一.复选框选中.反选.全选.全不选 html代码: <input type='checkbox' name='menuCheckBox' value='10' >苹果 <input ...

  5. form表单传递对象数组

    ajax传递数组.form表单提交对象数组 在JSP页面开发中,我们常常会用到form表单做数据提交,由于以前一直只是使用 form表单提交单个对象,只要表单文本域的name值和接收的对象的属性名一致 ...

  6. Vue在v-for中给css传递一个数组参数

    需求就是将很多个数据,以进度条的形式展示在页面上,形成一个可视化. 接下来是html代码 <!DOCTYPE html> <html> <head> <tit ...

  7. JS传递对象数组为参数给后端,后端获取

    前端JS代码: var conditons = []; var test1 = new Object(); test1.name="1"; test1.id="2&quo ...

  8. SQL Server 存储过程 数组参数 (How to pass an array into a SQL Server stored procedure)

    Resource from StackOverflow 使用存储过程,如何传递数组参数? 1.分割解析字符串,太麻烦 2.添加Sql Server 自定义类型 sp_addtype 问题需求:需要向S ...

  9. 关于springMVC 传递 对象参数的问题

    1.前端请求必须是 post 2.前端数据data必须做 json字符串处理  JSON.stringify(data) 3. contentType: 'application/json', 4.@ ...

随机推荐

  1. 团体程序设计天梯赛-练习集L1-023. 输出GPLT

    L1-023. 输出GPLT 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个长度不超过10000的.仅由英文字母构成的 ...

  2. Windows下如何使用BOOST C++库 .

    Windows下如何使用BOOST C++库 我采用的是VC8.0和boost_1_35_0.自己重新编译boost当然可以,但是我使用了 http://www.boostpro.com/produc ...

  3. HeadFirst设计模式之观察者模式

    一.什么是观察者模式 观察者模式定义了一系列对象间一对多的关系,当主题对象的状态发生变化时,会通知所有观察者 二.自定义观察模式 1. 2. package headfirst.designpatte ...

  4. *JRebel 热部署

    Jrebel是一套商业Java开发软件,可快速实现热部署,节省大量重启时间,提高开发效率. 去IDEA的插件官网下载插件:http://plugins.jetbrains.com/plugin/444 ...

  5. 1400 - "Ray, Pass me the dishes!"

    哈哈,原来题意看错了,但有多个解的时候,输出起点靠前的,如果起点一样,则输出终点靠前的,修改后AC的代码如下: #include <cstdio> #include <iostrea ...

  6. Eclipse反编译工具Jad及插件JadClipse配置(转)

    Eclipse反编译工具Jad及插件JadClipse配置 Jad是一个Java的一个反编译工具,是用命令行执行,和通常JDK自带的java,javac命令是一样的.不过因为是控制台运行,所以用起来不 ...

  7. 部分常见ORACLE面试题以及SQL注意事项

    部分常见ORACLE面试题以及SQL注意事项 一.表的创建: 一个通过单列外键联系起父表和子表的简单例子如下: CREATE TABLE parent(id INT NOT NULL, PRIMARY ...

  8. linux切换用户

    当前使用root账户 [root@localhost chucklu]# cd[root@localhost ~]# pwd/root 切换到普通账户 [root@localhost ~]# su c ...

  9. 将OutLook.exe注册为服务,让其一直保持开启状态

    类似于TaobaoProtect.exe是由TBSecSvc服务启动的 http://stackoverflow.com/questions/3582108/create-windows-servic ...

  10. 一个解决方案下的多个项目共享一个AssemblyInfo

    http://stackoverflow.com/questions/18963750/add-file-as-a-link-on-visual-studio-debug-vs-publish htt ...