Best way to do Spring MVC without JSP? [closed]
开发者_Go百科
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this questionI wish to use Spring MVC to provide a REST web service. However, running through some books and tutorials, it looks like ModelAndView always returns a parsed JSP file. I guess I could make the JSP build my XML document, but is this the best way to go about things? I thought that perhaps a more structured XML building approach might be appropriate.
What are my options? Also, does anyone have any relevant tutorials?
This would probably help somewhat. It seems you are looking for a Marshalling View.
Alternatively, a JAX-RS implementation like Jersey or RESTeasy might suit you as well.
The View part of ModelAndView does not have to represent a JSP.
See chapter 17 of the reference manual, for example in chapter 17.5 they describe how to set up a XSLT view (not what you need, but shows how different views are supported).
http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch17s05.html
Have you considered integrating Spring with RESTlet library? This page might be a good starting point...
There are a number of options for marshaling java beans into either XML or JSON. I use the spring-json package for rendering my model into JSON for my web service, and there are several choices if you want to render XML instead.
You could check out Freemarker. Basically, XML is just text, and by using a templating system you could easily create your XML document that you want to return.
You can have a look on http://www.jprovocateur.org . You can have a look on the online example and on the documentation on how the results are transformed in JSON/XML
Regards, Michael
Using Angularjs is an awesome idea. It does require you to do spring restfull services. Here is an article about it: https://www.webcodegeeks.com/javascript/angular-js/migrating-spring-web-mvc-jsp-angularjs/
精彩评论