记spring mvc传入List<Object>的一次尝试
首先,看一段异常:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unrecognized token 'entityList': was expecting ('true', 'false' or 'null')
标记的是实体中定义的属性值,实体如下:
@Data
public class ColumnsVO { List<GridColumnInfoEntity> entityList = new ArrayList<>(); }
前端js代码:
$.ajax({
url: 'grid/add.columns',
type: "POST",
data: {
entityList: rows
},
success: function (data) {
layer.msg(data.message);
},
dataType: "json",
contentType: "application/json"
});
controller处理代码:
@RequestMapping(value = "/add", consumes = "application/json; charset=utf-8")
public EasyuiResponse addColumns(@RequestBody ColumnsVO columnsVO) {
System.out.println(JSON.toJSONString(columnsVO));
return new EasyuiResponse(EasyuiResponse.SUCCESS, "配置成功!");
}
之前$.ajax中data一直是使用{key:value}方式,这次也不例外,结果就报错了。。。
搜索、查找后解决方案:
$.ajax({
url: 'grid/add.columns',
type: "POST",
data: JSON.stringify({
entityList: rows
}),
success: function (data) {
layer.msg(data.message);
},
dataType: "json",
contentType: "application/json"
});
和上面比,只有一点区别,将{key:value}使用JSON.stringify({key:value})转化为String后,一切正常!
一个比较奇怪的问题,记之。。。
另:spring mvc中传入集合需要注意的点:
1、看代码:
@RequestMapping(value = "/add", consumes = "application/json; charset=utf-8")
public EasyuiResponse addColumns(@RequestBody ColumnsVO columnsVO) {
System.out.println(JSON.toJSONString(columnsVO));
return new EasyuiResponse(EasyuiResponse.SUCCESS, "配置成功!");
} 标记部分需要注意!
2、则是上文讨论部分,注意之!
记spring mvc传入List<Object>的一次尝试的更多相关文章
- spring mvc 传入中文参数乱码问题解决
一个简单的学习springmvc的demo中,当http请求传入中文参数时,在controller中接受到的参数就已经是乱码了,经百度一番解决方案如下: 1. get请求方式乱码解决 对于get方式, ...
- spring mvc传入参数不仅仅转换为json,还可以直接将json字符串转换为具体的java对象
1.controller层 /** * 查看主播资料 * * @return */ @RequestMapping(value = { "/actor_details" }, me ...
- Spring MVC和Struts2的比较(二)
1.Spring MVC的controller+command object模式比Struts2的Action模式更安全一些.而在Struts2中,自动数据绑定发生在Action对象上.这样,在Act ...
- Injecting and Binding Objects to Spring MVC Controllers--转
I have written two previous posts on how to inject custom, non Spring specific objects into the requ ...
- spring MVC 如何接收前台传入的JSON对象数组并处理
spring MVC 如何接收前台传入的JSON对象数组 主要方法: (主要用到的包是 net.sf.json 即:json-lib-2.3-jdk15.jar 完整相关jar包: commons- ...
- spring MVC 如何接收前台传入的JSON对象数组
spring MVC 如何接收前台传入的JSON对象数组 主要方法: (主要用到的包是 net.sf.json 即:json-lib-2.3-jdk15.jar 完整相关jar包: commons- ...
- 当使用Spring MVC @Valid对输入框进行验证的时候,可能会遇到以下的异常:Neither BindingResult nor plain target object for bean name ‘mybean’ available as request attribute
转自:https://www.cnblogs.com/wenhulu/p/5555457.html 当使用Spring MVC @Valid对输入框进行验证的时候,可能会遇到以下的异常: Neithe ...
- Spring MVC 解决 Could not write JSON: No serializer found for class java.lang.Object
Spring MVC 解决 Could not write JSON: No serializer found for class java.lang.Object 资料参考:http://stack ...
- spring mvc踩坑记
前言 主要介绍自己在学习spring mvc过程中踩到的一些坑,涉及到当时遇到这个错误是如何思考的,对思路进行总结,下次遇到类似的错误能够提供一些思路甚至快速解决. 环境准备 jdk8,spring4 ...
随机推荐
- Win10 pip install gensim 报错处理
# 故障描述 shell > pip install gensim # 报错信息如下: Command "c:\users\op\appdata\local\programs\pyth ...
- redis启动.停止.重启
Linux下安装 ]# wget http://download.redis.io/releases/redis-2.8.17.tar.gz ]# tar xzf redis-2.8.17.tar.g ...
- How a non-windowed component can receive messages from Windows
Why do it? Sometimes we need a non-windowed component (i.e. one that isn't derived fromTWinControl) ...
- 尴尬!Jsp内置对象
今天挺尴尬的,上网络安全课做错了ppt ,尴尬到头皮发麻. JSP内置对象 JSP内置对象是Web容器创建的一组对象,不使用new关就可以使用的内置对象. <%int[ ]value= {60, ...
- scikit Flow ,tensor flow 做ml模型
[https://github.com/ilblackdragon/tf_examples/blob/master/titanic.py] [keras 高层tensorflow] https://k ...
- mysql允许远程登录
Mysql为了安全性,在默认情况下用户只允许在本地登录,可是在有此情况下,还是需要使用用户进行远程连接,因此为了使其可以远程需要进行如下操作: 一.允许root用户在任何地方进行远程登录,并具有所有库 ...
- go 第一个项目
官方下载go: https://golang.org/dl/ 安装完成后:cmd命令下:go go env:查看当前的环境配置:
- Cache Server
[Cache Server] Whenever a source Asset like a .psd or an .fbx file is modified, Unity detects the ch ...
- python OSError: [Errno 22] Invalid argument: 'D:\\crawle\x01.html1'
import urllib.request file = urllib.request.open("http://www.baidu.com") data = file.read( ...
- The Doors(几何+最短路,好题)
The Doors http://poj.org/problem?id=1556 Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...