I've been thinking all the day about how I can setup Spring MVC 3.0 (more specifically REST capabilities), with GWT. That is, I don't wanna use GWT RPC anymore, the communication will be made through REST. The problem is that I'm very new with the Spring Framework, and the only tutorials I found, they were using JSP, that's exactly where I get stuck... Is there a way to play with Spring without JSP page, only using the GWT view?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I assume what your trying to do is have a Spring controller return JSON or XML data?
There are two ways to do this:
- use a ContentNegotiatingViewResolver
- use HttpMessageConverters in combination with the @ResponseBody annotation
Both methods are covered in some detail here : http://hillert.blogspot.com/2011/01/rest-with-spring-contentnegotiatingview.html
The spring people cover the @RequestBody method here: http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/
Here is the blog post covering the ContentNegotiatingViewResolver : http://blog.springsource.com/2009/03/08/rest-in-spring-3-mvc/
Sample code can be found at : https://src.springframework.org/svn/spring-samples/mvc-ajax/trunk/
I hope this helps.