2012-03-04 53 views
0

我正在开发Spring MVC应用程序。此应用程序期望客户端在请求正文中发送XML。我怎样才能从正文中提取这个XML,然后创建一个DOM对象? 我使用Spring 3.0Spring MVC流程发布数据

由于 阿迪

回答

2

使用@RequestBody annotation

的@RequestBody方法参数注释指示的方法 参数应绑定到HTTP请求正文的值。对于 例如:

@RequestMapping(value = "/something", method = RequestMethod.PUT) 
public void handle(@RequestBody String body, Writer writer) throws IOException 
    writer.write(body); 
} 

通过使用一个 HttpMessageConverter请求体转换为方法参数。 HttpMessageConverter负责将 从HTTP请求消息转换为对象并将 从对象转换为HTTP响应正文。该 RequestMappingHandlerAdapter支持与 的@RequestBody注释以下默认HttpMessageConverters:

ByteArrayHttpMessageConverter converts byte arrays. 

StringHttpMessageConverter converts strings. 

FormHttpMessageConverter converts form data to/from a MultiValueMap<String, String>. 

SourceHttpMessageConverter converts to/from a javax.xml.transform.Source. 
+0

所以身体参数将包含XML?我可以使用SourceHttpMessageConverter来获取DOM吗? – adi 2012-03-04 15:52:30