Download presentation
Presentation is loading. Please wait.
Published byRoger Wheeler Modified over 9 years ago
1
Struts Petstore Struts University Series
2
Abstract Struts has always shipped with a simple example application. But for many teams, MailReader is a bit too simple. Struts Petstore is a full-featured, production-grade Struts application inspired by the infamous Java Pet Store. Struts Petstore uses a professional architecture that hooks up to Apache iBATIS for data access. Let's have a look...
3
Struts PetStore
14
A little background Sun creates J2EE Pet Store Demonstrates patterns Microsoft creates.NET Pet Shop Demonstrates performance Clinton Begin creates JPetStore Demonstrates iBATIS
15
iBATIS and Struts iBATIS Data mapping framework for SQL Compares to Hibernate and OJB Struts Web application framework Compares to WebWork and Tapestry Clinton Begin Inventor of iBATIS and author of JPetStore
16
The Purpose of JPetStore Clinton Begin wrote JPetstore to show Java is easy Java is low cost Java is highly productive Java enables choice Java enables change
17
The Purpose of JPetStore Clinton Begin wrote JPetstore to show Java is easy Java is low cost Java is highly productive Java enables choice Java enables change iBATIS is cool
18
Advantages without Tradeoffs JPetStore uses superior design and architecture Clearly defined application layers Uses known best practices and patterns Avoids known worst practices No stored procedures No SQL embedded in Java code No HTML in the database No generated code
22
Presentation Model View Controller Pattern Well know and proven (GOF) Simple and maintainable Apache Struts Freely available, open source Based on JavaBeans
24
Domain JavaBeans Components with properties and behavior Plug into presentation and persistence layers Compatible with many frameworks GUI tools available (IDEs, et cetera) Logic Classes None/Verb separation More maintainable than prior versions
26
Persistence Data Access Objects “Pluggable” persistance components Proven abstract factory pattern (GoF) Improves maintainability and flexibility SQL Maps Reduces/eliminates repetive JDBC code Improves performance with caching Portable across many databases Based on JavaBeans
28
Link to a category query JavaServer Page: Struts Config: <action path="/shop/viewCategory" type="com.ibatis.struts.BeanAction" name="catalogBean" scope="session" validate="false" >
29
CatalogBean public String viewCategory() { if (categoryId != null) { productList = catalogService.getProductListByCategory(categoryId); category = catalogService.getCategory(categoryId); } return "success"; }
30
CatalogService public PaginatedList getProductListByCategory(String categoryId) { return queryForPaginatedList("getProductListByCategory", categoryId, PAGE_SIZE); } public Category getCategory(String categoryId) { return (Category) queryForObject("getCategory", categoryId); }
31
SqlMaps select CATID, NAME, DESCN from CATEGORY select CATID, NAME, DESCN from CATEGORY where CATID = #value#
32
ResultMap
33
Cache Model
34
Cache Model
35
Dynamic SQL select CATID, NAME, DESCN from CATEGORY select CATID, NAME, DESCN from CATEGORY where CATID = #value#
36
Dynamic SQL select CATID, NAME, DESCN from CATEGORY where CATID = #value#
37
Struts University Series
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.