springmvc 传递复杂对象参数报 property path is neither an array nor a List nor a Map
来源:互联网 发布:vb编程界面 编辑:程序博客网 时间:2024/06/15 21:54
Spring MVC : Property referenced in indexed property path is neither an array nor a List nor a Map
JQuery的$.ajax在将json对象映射到参数方面做得非常出色,但是当你开始尝试传输更复杂的对象时(比如对象里包含对象),Spring MVC并不知道如何解释它。
例如,如果你有一个像这样的json对象:
{ "beans":[ { "agreemendId":1, "answerId":2 } ]}
SpringMVC中的接收参数如下:
@ResponseBodypublic 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....}
JQuery 会将你的参数映射成这样:
beans[0][agreementId]=1beans[0][answerId]=2
问题是Spring MVC需要这种的参数格式:
beans[0].agreementId=1beans[0].answerId=2
一种就是使用简单粗暴的手段,修改你建立JSON对象的代码。另一种方法是扩展jQuery插件以不同的方式构建参数。
改变javascript代码非常简单,看起来像这样:
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); }});
要使用jquery插件进行修改,建议看看这里。
-----------------------------------------------------------------------------
上文转载自 https://www.cnblogs.com/pautcher/p/6075422.html ,本文对英文部分进行了适当的翻译。
阅读全文
0 0
- springmvc 传递复杂对象参数报 property path is neither an array nor a List nor a Map
- [launch] is neither a launch file in package [urdf_sim_tutorial] nor is [urdf_sim_tutorial] a launch
- It's likely that neither a Result Type nor a Result Map was specified
- GeoServer 报 Can't find neither a FeatureType nor a CoverageInfo解决办法
- [fake_turtlebo.launch] is neither a launch file in package [rbx1_bringup] nor is [rbx1_bringup] ...
- [工作点滴]It's likely that neither a Result Type nor a Result Map was specified
- <restriction> element was found that has neither a base [attribute] nor a <simpleType> element among
- BUG_tomcat启动报错Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Ubuntu中crosstool-ng编译出错:[ERROR] gtype-desc.c:8829:18: error: subscripted value is neither array nor
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Table is neither enables nor disabled in HBase
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Linux中的文件IO
- 《Recent Advances in Convolutional Neural Networks》(一)
- 大神前端博客
- next_permutation
- vue.js移动端从一个购物车入门vuex环境搭建
- springmvc 传递复杂对象参数报 property path is neither an array nor a List nor a Map
- C语言实现堆排序算法
- java.lang.UnsatisfiedLinkError: no jacob-1.17-x64 in java.library.path
- 关于导入表
- HPU 1413: StarFarming [最短路]
- python tkinter练习小程序
- MapReduce典型编程场景——全局计数器
- 原型模型的简单使用
- threejs学习心得(场景的搭建+运动模型导入)