springmvc + jason ajax

1.千万不能吧@requestBody后面的类,放在controller里面作为内部类。否则会有http415错误。

2util:list的配置

<beansxmlns="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:oxm="http://www.springframework.org/schema/oxm"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:util="http://www.springframework.org/schema/util"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-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/oxm

http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/util

http://www.springframework.org/schema/util/spring-util-2.0.xsd">

3:MappingJacksonHttpMessageConverter的配置

<bean

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

<propertyname="messageConverters">

<util:listid="beanList">

<refbean="mappingJacksonHttpMessageConverter"/>

</util:list>

</property>

</bean>

<beanid="mappingJacksonHttpMessageConverter"

class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>

4.ContentNegotiatingViewResolver的配置(这个由可能不需要)

<propertyname="mediaTypes">

<map>

<entrykey="json"value="application/json"/>

<entrykey="html"value="text/html"/>

</map>

</property>

5.用json.min.js里面的postjson来发出ajax请求

6.需要json-core和json-mapper两个包

相关推荐