您的位置:首页 > 编程语言 > Java开发

Spring MVC 3.2 ajax 406 修正配置

2014-08-20 00:00 337 查看
摘要: ...
MVC将自动把前台的JSON数据转换为User,自动把Map转换为JSON返回前台。

<?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:p="http://www.springframework.org/schema/p"
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.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 
<context:component-scan base-package="*" />
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
<property name="favorParameter" value="false" />
<property name="ignoreAcceptHeader" value="false" />
<property name="mediaTypes">
<value>
atom=application/atom+xml
html=text/html
json=application/json
*=*/*
</value>
</property>
</bean>
...
</beans>

注意其中:mvc-3.2.xsd

http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

导入 jackson-core、jackson-mapper两个jar包

Controller中

@RequestMapping(value="/checkUserName")
public @ResponseBody Map<String, Object> checkUserName(@RequestBody User user){
Map<String, Object> resultMap = new HashMap<String, Object>();
return resultMap;
}

MVC将自动把前台的JSON数据转换为User,自动把Map转换为JSON返回前台
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Spring MVC 3.2 ajax 406