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
take a look at the ContentNegotiatingViewResolver
there's a similar question on the Spring forums.
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."
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
You can use RooAddon that setup the content negotiation for you: http://tzolov.blogspot.com/2010/05/spring-roo-addons-jaxb2-binding-and.html
For JSON support you can find at springsource.org some introduction.
It's mainly activating JSON support for the domain entities via
json all
or
json add
and then setting up the MVC controllers via the following roo command:
web mvc json all
精彩评论