Eclipse+struts+hibernate's Internet Store

Source: Internet
Author: User
Tags object functions implement log reference window domain access
Internet

This article describes the development tools and architectures needed for the development of a network store.

   Basic Configuration

Develop the development tools needed for this example.

• Development platform: Eclipse 3.1.

· Web server: Tomcat 5.

• Development technology: Jsp,struts Framework, Hibernate technology, JSTL.

• Database server: MySQL5.0.

   System Requirements

Most readers have the experience of online shopping, in the shopping site can be very convenient to register, browse the merchandise, inquire about goods, purchase only a few pointsMouse。 The network store in this chapter implements the basic functions described above, where users can register, browse merchandise, and search for a shopping cart in a Web store. Here's how each system function is explained.

1. Login and Registration

User Login and registration is the realization of a new user registration and the login of the old user, these two features are basically available on each ecommerce website. User registration is a new user can be in the network store information registration, this is the premise of shopping. Users must register before they can go shopping. Registration information is validated by the system to ensure the correctness of the registration information. User login is the user can landing on the landing page, in the shopping checkout, the user needs to login information, of course, when entering the system began, users can login. When landing, if the username password is incorrect, the system prompts for an error.

2. Product Browsing

The product browsing is realizes the user may browse the merchandise in the network shop, the commodity is according to the commodity category to carry on the classification, the user may click each category link to enter each classification, the view detailed information. After entering each commodity category, the goods are sorted according to the type of each product.

For example, to enter the large category of books, there can be many kinds of books, such as computer-related books, management related books. Users enter each product line according to each product link. For example, click on a computer-related book, and after entering, list every item. Click on each item to see the specific information of each item, such as clicking on the art of computer programming, you can see the publication date of the book, the Price, the book's approximate content. If you think this book is suitable, you can put it in the shopping cart.

3. Checkout

At the checkout time, the system willShowThe goods already in the user's shopping cart, including the product name, product quantity, unit price, total prices and whether there is stock. When the order is finalized, the user can modify the quantity of each item. For example, computer programming and art want to buy 2, then the user can modify its purchase quantity, update the cart can be. If the user does not want to buy this book, it can be removed from the shopping cart. But once you click the settlement to generate an order, the cart cannot be changed.

Based on the above general requirements, draw a use case diagram for the network store, as shown in Figure 1.

  
Figure 1 Use case diagram


   system Function Description

In this section, the reader is presented with the most intuitive way to introduce the functionality to be implemented by the entire system.

1, User Registration

User registration is one of the basic functions of the network store. If a user wants to buy a product from an online store, he or she must have a network Store account. Users can get an account by registering. Register the page effect as shown in Figure 2.

When the registration is successful, it will enter the home page of the online store. At this time already with the new account log in the network store, the system page of the homepage as shown in Figure 3. At the time of registration, the system will make some simple verification of the registration information, if the information format is not correct, then the registration will fail, the system will be prompted for failure, registration failure as shown in Figure 4.

  
Figure 2 Registering the page

  
Figure 3 Registration success

2, User Login

When a user already has an account, they can log in. When the user Login system home page, you can click on the login link. The login page is shown in Figure 5. If the login succeeds, it is returned to the home page of the system, and if the login fails, it will go to the failed pages, as shown in Figure 6.

  

Figure 4 Registration failed
  
Figure 5 Login Page

After the user has successfully logged in, there is a link in the upper-right corner of the system, click Enter to modify the contact information, as shown in Figure 7.

  
Figure 6 Logon Failure

  
Figure 7 Modifying personal information

3. Browse Merchandise

Once the user has successfully logged in, they can browse the products in the online store. On the home page there are several varieties of goods available for users to choose from, such as electronic goods, books and software. For example, the user clicks on the software to access the SOFTWARE product and the SOFTWARE PRODUCT is divided into Microsoft and Kingsoft, as shown in Figure 8.

After entering a product variety, the system will list all the product lines under this product variety, each product series has a lot of specific products, such as user click Microsoft, as shown in Figure 9.

  
Figure 8 Browsing Merchandise

  
Figure 9 Viewing specific products

A specific item is listed on the page in Figure 9, and the user can click on each item name to see the specific information of the item. For example, click Anti Spy, as shown in Figure 10.

4. Shopping

When a user browses to a product, he or she can put it in their cart. Each item has a link that is provided into the shopping cart. Click into the shopping cart as shown in Figure 11.

  
Fig. 10 Specific information of commodity

  
Figure 11 View Shopping Cart

There are many options to view the shopping cart page, such as deleting a shopping cart. When the user clicks Delete, as shown in Figure 12, the system will still jump to the shopping cart page. If the user feels that the quantity of a product is not appropriate, the user can change the quantity of the item, fill in the quantity to be purchased in the column, and click the Update cart, as shown in Figure 13.

  
Figure 12 Deleting a product

  
Figure 13 Changing the number of items

5. Checkout

After you view the cart, if the user wants to checkout, click the Checkout link, as shown in Figure 14. Click the next link to view the details of the order, as shown in Figure 15

  
Figure 14 Checkout
  
Figure 15 Order Details

After you view the order details, and then click the next link, the order is confirmed, as shown in Figure 16

After the order is confirmed, the order is generated. If you click the next link to generate an order, the order cannot be modified at this time. As shown in Figure 17.

  
Figure 16 Confirmation Order
  
Figure 17 Order Generation

   System Design

After analyzing the requirements of the system, we begin to design the whole architecture of the system. The focus of this chapter is on how to develop, not on how to design. Therefore, this part of the design is simply introduced to make it easier for readers to understand the entire system.

1. System Architecture Design

The entire application follows a multi-level architectural pattern, from top to bottom to the view layer, the controller layer, the model layer, the persistence layer, and the database layer, as shown in Figure 18. The front three floors are essentially the basic level of the struts framework. The persistence layer is created by hibernate.

  
Figure 18 System architecture

Among them, the relationship between the model layer, the persistence layer, the database layer is that the upper layer relies on the next level, and the next layer has little reliance on the previous layer, like the ISO seven-layer model of the network. The dependencies between levels should be top-down, that is, the upper layer can rely on the lower layer, while the lower level should minimize dependency on the upper layer.

For example, if you use hibernate in your system to implement the persistence layer, you do not need to change the code in your business logic to implement the persistence layer with other mechanisms. Both the view layer and the controller layer are implemented through the struts framework. The model layer can actually be subdivided into data access layer (DAO) and Data Service layer (Manager). The persistence layer is implemented using Hibernate, and the DAO pattern is used at this level, so this layer can be divided into data access layer and data service layer.

2. Business entity Design

The business entity of a system inMemoryis manifested as the entity domain object, in the database manifests as the relational data, realizes the business entity to include the following content.

• Design a domain model and create a domain model entity object.

• Design a relational data model.

• Create an object-relational mapping file.

The following business entities are in the network store: users, specific goods, commodity categories, commodity categories, orders, order items, shopping carts and specific items in the shopping cart. A simple explanation of these business entities is provided below, which is explained in detail later in this chapter.

• User: Represents a user entity, mainly including user details, such as user name, password, address, and so on.

• Specific commodities: represents each specific commodity information, such as the above mentioned computer programming art, mainly including the name of the commodity, price and so on.

• Commodity series: Represents a series of commodities, such as the previous reference to computer-related books.

• Product Category: Represents a category of goods, such as the book mentioned earlier.

• Order: On behalf of the user's order, mainly including the order name, user information, the specific content of the order.

• Order item: Represents a specific item in an order, and an order item includes the purchase of a commodity.

• Shopping Cart: Represents the user's shopping cart, is a virtual concept.

• Specific items in a shopping cart: represents each specific item in a shopping cart.

The relationships between these entities are shown in Figure 19.

  
Figure 19 Business entity Relationship Diagram

As shown in Figure 19, here is an introduction to the correspondence between the entities.

• Users and Orders: A user can have multiple orders, an order can only belong to a user, the relationship between them is a one-to-many relationship. In a database table, it behaves as a foreign key with a user table in the order table, and in hibernate it is represented by a user-persisted class reference in the order persistence class.

• Order and Order items: One order can have many order items, one order item is only a package for a specific product. The relationship between an order and an order item is represented in hibernate as a persistent class reference for an order in one order item.

• Order Items and merchandise: An order item is the package of goods, a commodity is the details of this commodity, in addition to the order of the product information, as well as the purchase quantity of this commodity, belong to which order.

• Commodity series and merchandise: A product series has multiple commodities, as computer-related books and computer programming art relationship.

• Commodity categories and commodity series, a commodity category has multiple commodity series, as the book and computer books on the relationship.

Shopping cart and shopping goods, the user's shopping cart can have a number of shopping items, because it is online shopping, perhaps a shopping cart in a stock of goods in the shopping cart, so the shopping product must have this information.

• Shopping goods and commodities, this relationship with the order items and goods, similar to the relationship between the goods, but shopping goods for the packaging angle is not the same, shopping goods in addition to record the quantity of goods also need to record its inventory.

The above is the definition of the relationship between all the entity domain models in the system.

3. Business logic Design

In this system, the application persistence layer adopts hibernate as middleware, and uses DAO design mode to realize access to the data layer. DAO mode is one of the core models of Java EE, whose main behavior is to add another layer between the business core method and the concrete data source, and use this layer to connect the business method and the data source, thus realizing the decoupling of the two.

Because specific persistence layer data sources can be diverse, either XML or relational databases. In a specific relational database, it may also be a different product, such as Oracle or MySQL. By using DAO mode, the business core does not care about how the data tier implements operations on the database, but only its own business operations, and the operation of the database is still given to the DAO proxy, as shown in Figure 20.

  
Figure DAO Mode



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.