* Much easier installation
* 31% better performance
* Tomcat support (for embedded usage)
* JMS support (including ActiveMQ setup)
* Selenium support
* Email support
* Web Flow installation
* Additional samples
* Various other fixes and improvements
在 Spring Roo 提供完整的官方文檔之前 ,SpringSource 網(wǎng)站博客上提供入門文章 便是不可多得的學習資料,我這里也是根據(jù)文章進行操作的。
從 SpringSource 網(wǎng)站上下載 Spring ROO 1.0.0 m1 ,解壓到硬盤上。
將 <spring_roo_dir>/bin 加入到系統(tǒng)的PATH變量中。在 Linux 系統(tǒng)上,你可以直接創(chuàng)建一個鏈接到 ~/bin 或 /usr/bin/ 中。
Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.
任何時候你可以輸入hint 來獲得一些操作建議。
roo> hint
Welcome to Roo! We hope you enjoy your stay!
Before you can use many features of Roo, you need to start a new project.
To do this, type 'create project' (without the quotes) and then hit TAB.
Enter a -topLevelPackage like 'com.mycompany.projectname' (no quotes).
When you've finished completing your -topLevelPackage, press ENTER.
Your new project will then be created in the current working directory.
Note that Roo frequently allows the use of TAB, so press TAB regularly.
Once your project is created, type 'hint' and ENTER for the next suggestion.
You're also welcome to visit http://forum. for Roo help.
roo> cre
這時按 Tab 鍵,你會發(fā)現(xiàn) Spring Roo 會幫你自動補全命令 create project。
Linux 用戶對 Tab 的使用再也熟悉不過了,在 Spring Roo 的命令行,你隨時都使用 tab 來輔助命令的輸入。
roo> create project
這里按下 enter ,會得到一條提示信息。
You must specify a default option (otherwise known as option 'topLevelPackage') for this command
roo> create project -topLevelPackage roodemo
Created /home/hantsy/Projects/roodemo/pom.xml
Created SRC_MAIN_JAVA
Created SRC_MAIN_RESOURCES
Created SRC_TEST_JAVA
Created SRC_TEST_RESOURCES
Created SRC_MAIN_WEBAPP
Created SRC_MAIN_RESOURCES/applicationContext.xml
Created SRC_MAIN_WEBAPP/WEB-INF
Created SRC_MAIN_WEBAPP/WEB-INF/roodemo-servlet.xml
Created SRC_MAIN_WEBAPP/WEB-INF/web.xml
Created SRC_MAIN_WEBAPP/WEB-INF/jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/index.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/urlrewrite.xml
這里如果輸入hint,會得到以下信息。
roo> hint
Roo requires the installation of a JPA provider and associated database.
Type 'install jpa' and then hit TAB three times.
We suggest you type 'H' then TAB to complete "HIBERNATE".
After the -provider, press TAB twice for database choices.
For testing purposes, type (or TAB) HYPERSONIC_IN_MEMORY.
If you press TAB again, you'll see there are no more options.
As such, you're ready to press ENTER to execute the command.
Once JPA is installed, type 'hint' and ENTER for the next suggestion.
任何時候,不要忘記使用 hint 來獲得提示。
roo> install jpa -
按 tab 可以看到所提供的參數(shù)選項。
install jpa -database install jpa -provider
輸入 -p 按 tab 自動補全 -provider 。
roo> install jpa -provider
按 tab 可以看到幾種可用的 jpa 實現(xiàn)。
ECLIPSELINK HIBERNATE OPENJPA
接著輸入首字母 H 按tab,補全 HIBERNATE,再輸入-d 按 tab,補全-database。
roo> install jpa -provider HIBERNATE -database
H2_IN_MEMORY HYPERSONIC_IN_MEMORY HYPERSONIC_PERSISTENT
MSSQL MYSQL ORACLE
POSTGRESQL SYBASE
最后輸入MY 按 tab 選擇MySQL 數(shù)據(jù)庫。
roo> install jpa -provider HIBERNATE -database MYSQL
Created SRC_MAIN_RESOURCES/META-INF
Created SRC_MAIN_RESOURCES/META-INF/persistence.xml
Created SRC_MAIN_RESOURCES/database.properties
please enter your database details in src/main/resources/database.properties
Managed SRC_MAIN_RESOURCES/applicationContext.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
3. 創(chuàng)建 Domain Class
現(xiàn)在如果輸入 hint ,可以看到以下信息。
roo> hint
You can create entities either via Roo or your IDE.
Using the Roo shell is fast and easy, especially thanks to the TAB completion.
Start by typing 'new p' and then hitting TAB twice.
Enter the -name in the form '~.domain.MyEntityClassName'
In Roo, '~' means the -topLevelPackage you specified via 'create project'.
Afer specify a -name argument, press SPACE then TAB. Note nothing appears.
Because nothing appears, it means you've entered all mandatory arguments.
However, optional arguments do exist for this command (and most others in Roo).
To see the optional arguments, type '-' and then hit TAB. Mostly you won't
need any optional arguments, but let's select the -testAutomatically option
and hit ENTER. You can always use this approach to view optional arguments.
After creating an entity, use 'hint' for the next suggestion.
創(chuàng)建一個 Post 類。
roo> new persistent class jpa -name ~.domain.Post -
按下 Tab ,你有三種選擇,你可以創(chuàng)建一個抽象類,或者從其它類繼承。
new persistent class jpa -name ~.domain.Post -abstract
new persistent class jpa -name ~.domain.Post -extends
new persistent class jpa -name ~.domain.Post -testAutomatically
這里輸入 t 按 Tab 鍵選擇 -testAutomatically 同時創(chuàng)建一個測試類。
roo> new persistent class jpa -name ~.domain.Post -testAutomatically
Created SRC_MAIN_JAVA/roodemo/domain
Created SRC_MAIN_JAVA/roodemo/domain/Post.java
Created SRC_TEST_JAVA/roodemo/domain
Created SRC_TEST_JAVA/roodemo/domain/PostDataOnDemand.java
Created SRC_TEST_JAVA/roodemo/domain/PostIntegrationTest.java
Created SRC_MAIN_JAVA/roodemo/domain/Post_Roo_Plural.aj
Created SRC_MAIN_JAVA/roodemo/domain/Post_Roo_Entity.aj
Created SRC_MAIN_JAVA/roodemo/domain/Post_Roo_ToString.aj
Created SRC_MAIN_JAVA/roodemo/domain/Post_Roo_Configurable.aj
Created SRC_TEST_JAVA/roodemo/domain/PostIntegrationTest_Roo_Configurable.aj
Created SRC_TEST_JAVA/roodemo/domain/PostDataOnDemand_Roo_DataOnDemand.aj
Created SRC_TEST_JAVA/roodemo/domain/PostIntegrationTest_Roo_IntegrationTest.aj
Created SRC_TEST_JAVA/roodemo/domain/PostDataOnDemand_Roo_Configurable.aj
roo> add field string -fieldName title -notNull -sizeMax 200
roo> add field string -fieldName content -notNull -sizeMax 2000
roo> add field date jpa -fieldName createdDate -type java.util.Date
roo> add field date jpa -fieldName modifiedDate -type java.util.Date
創(chuàng)建另外一個類 Comment。
roo> new persistent class jpa -name ~.domain.Comment -testAutomatically
roo> add field string -fieldName name -notNull -sizeMax 200
roo> add field string -fieldName email -notNull -sizeMax 50
roo> add field string -fieldName content
roo> add field string -fieldName url
roo> add field date jpa -fieldName createdDate -type java.util.Date
添加關(guān)聯(lián)關(guān)系。
roo> add field set jpa -fieldName comments -element ~.domain.Comment -class ~.domain.Post -mappedBy post
roo> add field reference jpa -fieldName post -type ~.domain.Post -class ~.domain.Comment
roo> new controller automatic -formBackingObject roodemo.domain.Post -name roode roodemo.web.PostController
Created SRC_MAIN_JAVA/roodemo/web
Created SRC_MAIN_JAVA/roodemo/web/PostController.java
Created SRC_MAIN_JAVA/roodemo/domain/CommentEditor.java
Created SRC_MAIN_JAVA/roodemo/web/PostController_Roo_Controller.aj
Created SRC_MAIN_WEBAPP/images
Created SRC_MAIN_WEBAPP/images/banner-graphic.png
Created SRC_MAIN_WEBAPP/images/springsource-logo.png
Created SRC_MAIN_WEBAPP/images/list.png
Created SRC_MAIN_WEBAPP/images/show.png
Created SRC_MAIN_WEBAPP/images/create.png
Created SRC_MAIN_WEBAPP/images/update.png
Created SRC_MAIN_WEBAPP/images/delete.png
Created SRC_MAIN_WEBAPP/styles
Created SRC_MAIN_WEBAPP/styles/roo.css
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/header.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/footer.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/includes.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/dataAccessFailure.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/uncaughtException.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/post
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/post/list.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/post/show.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/post/create.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/post/update.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/menu.jsp
Managed SRC_MAIN_WEBAPP/WEB-INF/jsp/menu.jsp
Created SRC_MAIN_JAVA/roodemo/domain/CommentEditor_Roo_Editor.aj
roo> new controller automatic -formBackingObject ~.domain.Comment -name ~.web.CommentController
Created SRC_MAIN_JAVA/roodemo/web/CommentController.java
Created SRC_MAIN_JAVA/roodemo/domain/PostEditor.java
Created SRC_MAIN_JAVA/roodemo/web/CommentController_Roo_Controller.aj
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/comment
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/comment/list.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/comment/show.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/comment/create.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/comment/update.jsp
Managed SRC_MAIN_WEBAPP/WEB-INF/jsp/menu.jsp
Created SRC_MAIN_JAVA/roodemo/domain/PostEditor_Roo_Editor.aj