jQuery、SpringMVC@RequestBody和JSON-使其协同工作
@ResponseBody
@RequestMapping(value={"/fooBar/{id}"}, method=RequestMethod.GET) public @ResponseBody FooBar getFooBar( @PathVariable String id, HttpServletResponse response , ModelMap model) { response.setContentType("application/json");...}
$.getJSON('fooBar/1', function(data) { //do something});
@RequestMapping(value={"/fooBar/save"}, method=RequestMethod.POST)public String saveFooBar(@RequestBody FooBar fooBar, HttpServletResponse response , ModelMap model) { //This method is never called. (it does when I remove the RequestBody...)}
最新情况:
<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /> <!-- Bind the return value of the Rest service to the ResponseBody. --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <util:list id="beanList"> <ref bean="jsonHttpMessageConverter" /><!-- <ref bean="xmlMessageConverter" /> --> </util:list> </property></bean>
<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="jacksonMessageConverter" /> </list> </property> </bean>
慕的地6264312
郎朗坤
相关分类