RESTful 架构、Spring 与 Java EE
我正在尝试为我正在构建的一些新项目做出架构解决方案的决定。
这些项目需要是多平台的,移动设备、平板电脑、桌面设备等。 因此,为后端/服务器选择 RESTful api(json) 的原因。
我已经研究 Java EE 很长时间了,所以现在正在尝试 Spring 和 Java EE 6,但两者看起来都很简单,Spring 似乎有更多的配置和层。
我一直在研究 Spring 3.1 Rest 与 Java EE 6 Resteasy/Jersey。
一切都非常容易设置, Spring我使用了@EnableWebMvc和新的httpMessageConverters等 RestEasy/Jersey
在RestEasy/Jersey中似乎可以通过请求来确定Web服务返回的内容(json/xml/html...)在Spring中是不是也一样?
任何其他建议也会非常有帮助,
谢谢
I am trying to come to a decision on a architecture solution for some new projects that I am building.
These projects need to be multiplatform, mobile, tablet, desktop, etc.
So therefore the reason to choose a RESTful api(json) for the backend/server.
I have been working on Java EE for long time, so expirmenting with Spring and Java EE 6 at the moment, but both seem quite straightforward, Spring just seems to have so much more configuration and layers.
I have been looking at Spring 3.1 Rest vs Java EE 6 Resteasy/Jersey.
All have been pretty easy to setup,
Spring I used the @EnableWebMvc and the new httpMessageConverters, etc
RestEasy/Jersey
It seems in RestEasy/Jersey that the content returned by the web service can be determined by the request (json/xml/html...) Is it the same in Spring?
Any other advice would also be very helpful,
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Spring 相对于其他框架的一大优势是可以将几乎所有默认组件与您自己的组件进行交换。
在您的情况下,ContentNegotiationViewResolver 可能是最好的选择。默认情况下,它允许您通过接受标头、格式 url 参数或扩展名(例如 .json/.xml)确定请求的可传输类型。
请参阅以下内容以获取一些示例和说明: http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch18s02.html
The big advantage of Spring over other frameworks is the possibility to exchange almost all of the default compontents with your own.
In your case the ContentNegotiationViewResolver is probably the one to go. It allows you per default to determine the requested transferable type by the accept header, by the format url parameter or by extension (e.g. .json/.xml)
See the following to get some examples and explanations: http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch18s02.html
是的,返回的数据类型在 Spring 中可以改变。
您可以使用请求的接受标头或为请求提供参数。
请参阅此之前的答案。
Yes the returned datatype can be varied in Spring.
You can either use the accept-header of the request or supply a parameter with the request.
See this previous answer.