我将我的messageconverter配置为杰克逊的
class Foo{int x; int y}
Run Code Online (Sandbox Code Playgroud)
并在控制器中
@ResponseBody
public Foo method(){
return new Foo(3,4)
}
Run Code Online (Sandbox Code Playgroud)
从那个我期望从服务器返回一个JSON字符串{x:'3',y:'4'},没有任何其他配置.但得到我的ajax请求的404错误响应
如果使用@ResponseBody注释该方法,则将返回类型写入响应HTTP正文.返回值将使用HttpMessageConverters转换为声明的方法参数类型.
我错了吗 ?或者我应该使用序列化程序将我的响应对象转换为Json字符串,然后将该字符串作为响应返回.(我可以正确地进行字符串响应)或者我应该进行其他配置吗?比如为Foo类添加注释
这是我的conf.xml
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
Run Code Online (Sandbox Code Playgroud)
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jacksonMessageConverter"/>
</list>
</property>
Run Code Online (Sandbox Code Playgroud)