spring mvc ajax 提交复杂数组类型
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method
1、Spring Mvc 配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.test.controller">
</context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value=""></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html; charset=utf-8</value>
<value>application/json; charset=utf-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
</list>
</property>
</bean>
<mvc:annotation-driven />
<mvc:default-servlet-handler />
</beans>
引用 jackson jar包:jackson-annotations-2.1.1.jar、jackson-core-2.1.1.jar、jackson-databind-2.1.1.jar。
2、Controller代码
package com.test.controller; import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List; /**
* Created by Administrator on 2015/2/28.
*/
@Controller
@RequestMapping("/report")
public class ReportTypeController extends BaseController { @RequestMapping("/set")
@ResponseBody
public String set(@RequestBody List<User> settingBeans,HttpServletRequest request){return "";
}
}
3、ajax请求:
var userList= new Array();
userList.push({id:1,name:"zhangsan"});
userList.push({id:2,name:"lisi"});
$.ajax({
url: "/report/set",
type:"post",
data:JSON.stringify(userList),
dataType:"json",
contentType:"application/json",
success:function(data){
},error:function(data){
}
});
如果实体中某个boolean属性定义为isFirst,js中为此属性传值的时候应为:{first:true}之类
spring mvc ajax 提交复杂数组类型的更多相关文章
- Spring MVC ajax提交方式
使用jquery的ajax的方式来提交 第一种,以json对象的形式提交 var jsonData = { "name" : "zhangsan", " ...
- Spring MVC url提交参数和获取参数
[转载:http://blog.csdn.net/mahoking] 普通URL提交参数 该格式url为:url.do?param1=mahc¶m2=8888.00 需 ...
- mvc ajax提交数组参数(转)
http://blog.csdn.net/lonestar555/article/details/10192595/ 在action中的参数以数组方式接收数据 一.表单方式 1.提交Form < ...
- Spring MVC Ajax 嵌套表单数据的提交
概述 在一些场景里,某个大表单里常常嵌套着一个或若干个小逻辑块,比如以下表单里"设计预审"中包括了一个子模块表单"拟定款项". 在这种情况下该怎么去设计实体类以 ...
- Spring MVC+ajax进行信息验证
本文是一个ajax结合Spring MVC使用的入门,首先我们来了解一下什么是Ajax AJAX 不是新的编程语言,而是一种使用现有标准的新方法.AJAX 最大的优点是在不重新加载整个页面的情况下,可 ...
- spring mvc ajax异步文件的上传和普通文件上传
表单提交方式文件上传和ajax异步文件上传 一:首先是我在spring mvc下的表单提交方式上传 ssm的包配置我就不一一详细列出来了,但是上传的包我还是列出来 这一段我也不知道怎么给大家讲解就是直 ...
- Spring MVC请求参数绑定 自定义类型转化 和获取原声带额servlet request response信息
首先还在我们的框架的基础上建立文件 在domian下建立Account实体类 import org.springframework.stereotype.Controller; import org. ...
- Spring MVC 处理列表和数组数据
SpringMVC处理列表和数组类型: 当form提交多个参数时,可以使用@RequestParam(value="")注解将其注入到列表或数组中,否则参数无法传值 1 contr ...
- 在Spring MVC 中配置自定义的类型转换器
方法一: 实现spring mvc 自带的 Formatter 接口 1.创建一个类来实现Formatter接口 import org.springframework.format.Formatter ...
随机推荐
- javascript 函数执行上下文
在js里,每个函数都有一个执行的上下文,我们可以通过this来访问. 如: 全局函数 function test(){ var local = this; } 我们发现local等于window(do ...
- mysql - 最小缺失值查询
初始化数据 DROP TABLE IF EXISTS X; CREATE TABLE X( a INT UNSIGNED PRIMARY KEY, b ) NOT NULL )ENGINE=INNOD ...
- Blob(二进制)、byte[]、long、date之间的类型转换
String转成byte[]类型存入数据库,数据库字段对应byte[]的类型为Blob类型 String value = this.getParamNotNnll("bgvalue" ...
- eclipse 相同变量高亮显示 颜色修改 变量着色
问题描述: 在eclipse中使用快捷键或其他原因,不小心按错了,使得变量的高亮显示没了. 1.简单的办法: 网上搜了一下,原来是Toggle Mark Occurrences (Al ...
- IIS访问提示您不具备查看该目录或页面的权限,因为访问控制列表 (ACL) 对 Web 服务器上的该资源进行了配置
1. 检查IIS权限,webmail目录权限. 2. 在本地安全策略中,设置从网络访问本地服务器与拒绝从网络访问本地服务器.中查看相关用户的权限 3. 如果上面的步骤还是有问题.使用下面的步骤进行设置 ...
- XE3随笔8:关于乱码
以下例子都会出现乱码, 虽然都可以有变通的方案, 但如果不乱码就太好了! unit Unit1; interface uses Windows, Messages, SysUtils, Varia ...
- TextFile 类的创写
TextFile 作为自写的方法,继承自List<String>.像统计文本中出现的哪些单词,不重复等等,适合用Set集合完成统计. class TextFile extends Arra ...
- C# 读写excel 用于导入数据库 批量导入导出excel
给大家介绍一款控件,Aspose.Cells.dll,相当强大,几乎就是excel,支持excel2003,excel2007等格式文件.excel2010以上,没有经过测试,估计也是可以. Aspo ...
- Android多点触控技术实战,自由地对图片进行缩放和移动
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/11100327 在上一篇文章中我带着大家一起实现了Android瀑布流照片墙的效果, ...
- WebStorm License Activation (WebStorm许可证激活)
User or company name(用户或公司名称): EMBRACE License key(许可证密钥): ===== LICENSE BEGIN =====89374-12042010 ...