来自 Roo RESTful 控制器的 JSON 和 XML
我已经设置了 Spring Roo 项目,一切都很棒,但是视图是用 Tiles 渲染的,我希望将它们渲染为 JSON(可能是 XML),以便我可以直接将它们用作 Web 服务。你对我应该如何做这个“Roo方式”有什么建议吗?
干杯
尼克
I've got my Spring Roo project set up and it's all great, but the views are rendered with Tiles, and I'd love to have them just rendered to JSON (possibly to XML) so that I can use them directly as webservices. Do you have any suggestions to how I should do this "the Roo way"?
Cheers
Nik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看看 ContentNegotiatingViewResolver
Spring 论坛上有一个类似问题 。
take a look at the ContentNegotiatingViewResolver
there's a similar question on the Spring forums.
这可能会有所帮助...
http://www.youtube.com/watch?v=TNE7NBLseRA
Spring Roo 的 RESTful Web 服务
“在本截屏视频中,我们通过查看 Spring Roo 来继续探索支持 RESTful Web 服务的工具和框架。我们将使用我们过去使用过的示例字典服务。我们”将使用 Roo 的 JSON 支持来实现对 Word 资源的 GET、PUT、POST 和 DELETE 操作。”
This may help...
http://www.youtube.com/watch?v=TNE7NBLseRA
RESTful Web Services with Spring Roo
"In this screencast, we continue our exploration of tools and frameworks supporting RESTful Web Services by taking a look at Spring Roo. We'll use our example Dictionary service that we've used in the past. We'll use Roo's JSON support to implement the GET, PUT, POST, and DELETE operations on the Word resource."
我做了这样的项目并且效果非常好。
因此,您需要使用以下步骤来实现您的项目:
1-创建 Spring Roo 项目
2-将为您的项目打开 roo shell
顺序使用以下命令列表:
3-在 Roo shell 中,尝试按以下 -- project --topLevelPackage 你的包--projectName
b-- osgi start --url 你的 jdbc 路径 (file:////home/binov1/workspaceLiferay/postgresql-9.4-1201.jdbc4.jar -- 这是我的jdbc路径)
c-- jpa setup --provider HIBERNATE --database POSTGRES --hostName adresse --userName 你的用户名 --password 你的密码 --databaseName 的名称
你的数据库
d-- 数据库逆向工程师 --schema public --package 你的包。
e-- json all
f-- web mvc json setup
g-- web mvc json all
这个解决方案将对您有很大帮助,请尝试一下
I do this kind of project and it's worked very well.
So you need to use the following steps to achieve your project:
1-Create your Spring Roo project
2-The roo shell will be opened for your project
3-In the Roo shell, try to use this liste of commands in the order:
a-- project --topLevelPackage your package--projectName
b-- osgi start --url the path of your jdbc (file:////home/binov1/workspaceLiferay/postgresql-9.4-1201.jdbc4.jar -- it's my jdbc path)
c-- jpa setup --provider HIBERNATE --database POSTGRES --hostName adresse --userName your user name --password your password --databaseName name of
your database
d-- database reverse engineer --schema public --package your package.
e-- json all
f-- web mvc json setup
g-- web mvc json all
This solution will help you very well, try it
您可以使用 RooAddon 为您设置内容协商:
http://tzolov.blogspot.com/2010 /05/spring-roo-addons-jaxb2-binding-and.html
You can use RooAddon that setup the content negotiation for you:
http://tzolov.blogspot.com/2010/05/spring-roo-addons-jaxb2-binding-and.html
对于 JSON 支持,您可以在 springsource.org 找到一些介绍。
激活对域实体的 JSON 支持
它主要通过或
,然后通过以下 roo 命令设置 MVC 控制器:
For JSON support you can find at springsource.org some introduction.
It's mainly activating JSON support for the domain entities via
or
and then setting up the MVC controllers via the following roo command: