spring responsejson with responsebody [英] spring prefixjson 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屋!