springmvc中经过使用jackson配置来处理springmvc对json的支持,经过@ResponseBody来将后台对象转成json对象传给调用者,经过@RequestBody来将调用者传过来的json字符串转换为后台使用的对象具体配置以下html
在spring-mvc.xml中web
<
bean
id
=
"mappingJacksonHttpMessageConverter"
class
=
"org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"
>
<
property
name
=
"supportedMediaTypes"
>
<
list
>
<
value
>text/html;charset=UTF-8</
value
>
</
list
>
</
property
>
</
bean
>
<
bean
class
=
"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
>
<
property
name
=
"messageConverters"
>
<
list
>
<
ref
bean
=
"mappingJacksonHttpMessageConverter"
/>
</
list
>
</
property
>
</
bean
>
此时@ResponseBody已经能够正常向调用者输出json对象了,可是@RequestBody这个还不能正常的工做 还须要调用者配置 contentType:"application/json", 而后将json对象转换为json字符串 这样@RequestBody才能起做用,要否则就会报Unsupported media type 不支持这个类型。至此问题解决。好了,继续写代码了spring