spring responsejson with responsebody [英] spring prefixjson with responsebody

查看:93
本文介绍了spring responsejson with responsebody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当控制器方法返回@responsebody时,即使我把

when controller method return is @responsebody , even if i put

<bean
    class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
     <property name="prefixJson" value="true" />   
</bean>  

没有&& {}插入json数据的前面。有谁知道是什么原因?

there will no && {} insert at the front of json data. anyone knows what is reason?

推荐答案

中的JSON> @RequestBody / @ResponseBody MappingJacksonHttpMessageConverter 处理,该配置在 AnnotationMethodHandlerAdapter.messageConverters 。

JSON in @RequestBody/@ResponseBody is handled by MappingJacksonHttpMessageConverter which is configured in AnnotationMethodHandlerAdapter.messageConverters.

在不干扰其他功能的情况下配置它的简单方法是创建一个 BeanPostProcessor 来拦截创建 AnnotationMethodHandlerAdapter ,例如,参见这里

The easy way to configure it without interference with other features is to create a BeanPostProcessor to intercept creation of AnnotationMethodHandlerAdapter, see, for example, here.

这篇关于spring responsejson with responsebody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆