spring mvc ajax 提交复杂数组类型
2015-03-03 18:51
435 查看
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 配置
引用 jackson jar包:jackson-annotations-2.1.1.jar、jackson-core-2.1.1.jar、jackson-databind-2.1.1.jar。
2、Controller代码
3、ajax请求:
如果实体中某个boolean属性定义为isFirst,js中为此属性传值的时候应为:{first:true}之类
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提交json数组时415错误解决方法
- spring mvc ajax 提交复杂数组类型
- ###Springmvc封装复杂表单数据:表单提交多个实体类的参数【对象类型参数,自动封装】name属性值不能重复。和实体类属性名一致
- spring mvc ajax 提交复杂数组类型
- 当 ASP.NET MVC 邂逅 JQuery.Ajax 提交数组
- \t\t.net Mvc Controller 接收 Json/post方式 数组 字典 类型 复杂对象
- Spring Boot Ajax 提交对象类型
- SpringMVC + Spring + MyBatis 学习笔记:提交数据遭遇基础类型和日期类型报400错误解决方法
- MVC中用ajax提交json对象数组
- Spring MVC Ajax 嵌套表单数据的提交
- spring mvc ajax json数据类型交互 小例子
- Spring MVC Controller 接收ajax传来的数组参数
- 使用javaScript解决asp.net中mvc使用ajax提交数组参数的匹配问题
- SpringMvc+Spring4+hibernate框架 ajax提交JSON数据Controller接收
- SpringMVC + Spring + MyBatis 学习笔记:提交数据遭遇基础类型和日期类型报400错误解决方法
- springMVC @RequestParam ajax传递数组
- .net Mvc Controller 接收 Json/post方式 数组 字典 类型 复杂对象
- 使用javaScript解决asp.net中mvc使用ajax提交数组参数的匹配问题
- Ajax+SpringMVC传递JSON数组
- html+springMVC的拦截器token配置--解决ajax表单重复提交的问题