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 ...
随机推荐
- Web前端之CSS_day3-4
1.行高 1.1 初始行高 行高=文字大小+上间距+下间距 默认文字大小:16px 默认文字行高:18px 注意:行高=盒子的高度,可以让文字垂直居中显示 1.2 行高单位 a. px 行高设置多少就 ...
- Dobbo的继任者?试用微博RPC框架Motan
从14年开始就陆续看到新浪微博RPC框架Motan的介绍,时隔两年后,微博团队终于宣布开源轻量级RPC框架Motan,项目地址: https://github.com/weibocom/motan/ ...
- VC++ 浅谈VS2010中CMFCToolBar的用法
本文将给大家介绍Visual Studio 2010中CMFCToolBar的用法,CMFCToolBar可以让用户自定义工具栏图标,使用静态成员函数SetUserImages()将一个CMFCToo ...
- flex4.0密钥及破解方式
输入下面的序列号: 1424-4507-0757-7016-8907-6937 1424-4785-4428-8084-6314-8733 1424-4794-9281-8063-2338-9079 ...
- Quartus调用modelsim
1.Quartus 调用modelsim Test Bench Name :是test bench的文件名 Top Level module in test bench:test bench文件内的m ...
- 违反并发性: UpdateCommand影响了预期 1 条记录中的 0
今天遇到这个错误,看到下面这种说法都没解决问题: 1 检查是否设有主键.2 DeleteCommand的问题:检查是否含有自动编号字段(Access的自动编号字段可能会引发此异常): UpdateC ...
- mac--有用的命令和快捷键
有用的命令: 将man命令打开为pdf文件预览 man -t grep | open -f -a Preview 定位某文件的位置 locate htop 隐藏和显示桌面文件 chflags hidd ...
- HTTP协议-引自孤傲苍狼博客
一.什么是HTTP协议 HTTP是hypertext transfer protocol(超文本传输协议)的简写,它是TCP/IP协议的一个应用层协议,用于定义WEB浏览器与WEB服务器之间交换数据的 ...
- echo 换行不换行
echo换行输出需要转义符 -e 看以下例子: echo -e "It is the first line." >> a; echo -e "It is th ...
- js抽奖
http://www.aichengxu.com/view/64369 <!Doctype html><html><head><meta http-equiv ...