Spring Roo Docs(2)Pizza shop sample and backup

Spring Roo Docs(2)Pizza shop sample and backup

2.3. Tutorial Application Details
We will create a web site for a Pizza Shop. A pizza is composed of a base and one or more toppings.
Domain Models:
PizzaOrder
name:String
address: String
total:double
deliveryDate:Date
pizzas:Set<Pizza>

Pizza
name:String
price:double
toppings:Set<Topping>
base:Base

Topping
name:String

Base
name:String

2.4 Step 1: Starting a Typical Project
>mkdir pizza
>cd pizza
roo>project --topLevelPackage com.sillycat.pizzashop
roo>jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
Hibernate is the object-relational mapping(ORM) provider, it is one of three ORM providers which Roo currently offers.

Command to install a local file to our local maven repository
>mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.2 -Dpackaging=jar -Dfile=/path/to/file

2.5. Step2: Creating Entities and Fields
roo>entity jpa --class com.sillycat.pizzashop.models.Topping --testAutomatically
roo>field string --fieldName name --notNull --sizeMin 2

roo>entity jpa --class ~.models.Base --testAutomatically
roo>field string name --notNull --sizeMin 2
roo>entity jpa --class ~.models.Pizza --testAutomatically
roo>field string --fieldName name --notNull --sizeMin 2
roo>field number --fieldName price --type java.lang.Float

Try to create many-to-many relationships.
roo>field set --fieldName toppings --type ~.models.Topping

Try to create many-to-one relationships.
roo>field reference --fieldName base --type ~.models.Base

Create the PizzaOrder object.

2.6. Step 3: Integeration Tests
You can create integration tests alone with command "test integration", and run tests with command "perform tests".
roo>perform tests

2.7. Step 4: Using Your IDE
roo>perform eclipse

2.8. Step 5: Creating A Web Tier
roo>web mvc setup
roo>web mvc all --package ~.web

This command will scan the Pizza Shop project for any domain entities and scaffold a Spring MVC controller for each entity detected.

src/main/webapp folder, this folder includes graphics, cascading style sheets, Java Server pages, Tiles configurations and more.

2.9. Step 6: Loading the Web Server
>mvn tomcat:run
>mvn jetty:run

Visit http://localhost:8080/pizzashop to verify.

2.10. Securing the Application
roo>security setup

We need to secure the views for Topping, Base, and Pizza resources, so we change the configuration file applicationContext-security.xml file.
<intercept-url pattern="/pizzas/**" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/toppings/**" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/bases/**" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/resources/**" access="permitAll" />
<intercept-url pattern="/static/**" access="permitAll" />
<intercept-url pattern="/**" access="permitAll" />
<authentication-provider>
<user-service>
       <user name="admin" password="admin" authorities="ROLE_ADMIN" />
           <user name="user" password="user" authorities="ROLE_USER" />
       </user-service>
</authentication-provider>

Next step, I use spring security JSP tag library to restrict access to the relevant menu items in the menu.jspx
<div xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:sec="http://www.springframework.org/security/tags"
xmlns:menu="urn:jsptagdir:/WEB-INF/tags/menu" id="menu" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
<sec:authorize ifAllGranted="ROLE_ADMIN">
...snip...
</sec:authorize>
Leave the pizza order view visible to the public. Obviously the delete and update actions for pizza order view are not desirable. So I change the PizzaOrderController.java source:
@RooWebScaffold(path = "pizzaorders", formBackingObject = PizzaOrder.class, delete = false, update = false)

Login this page to verify http://localhost:8080/pizzashop/login.

2.11. Customizing the Look & Feel of the Web UI
/styles        style sheets(CSS)
/images      graphics
/WEB-INF/classes/*.properties  theme configurations
/WEB-INF/config/*.xml            Web-related Spring application contexts
/WEB-INF/i18n/*.properties     internationalization message files
/WEB-INF/layouts/layout.jspx   Tiles definition for master layout
/WEB-INF/tags/*.tagx             Tag libraries(paination, language, etc)
/WEB-INF/views/**/*              Tiles and other view artifacts

2.12. Selenium Tests
roo>selenium test --controller ~.web.ToppingController
roo>selenium test --controller ~.web.BaseController
...snip...
These commands will generate the selenium test codes and locate in src/main/webapp/selenium foler.
>mvn selenium:selenese

2.13. Backups and Deployment
roo>backup

This command will backup current workspace with all sources, log files and the script log file(excluding the target directory)

references:

books:
spring-roo-docs.pdf


你可能感兴趣的:(spring roo)