Java Web (14) write a summary of the Mybookstore project

Source: Internet
Author: User
Tags unique id uuid java web

These days have not been sent blog, the reason is to write a small project in the bookstore, as the final precipitation of web learning, the next to the framework of learning. The project will eventually share the source link. Students who need it can get their own play.

--wh

I. Introduction of the Project

From the Internet to find a training institutions of small projects, the name is called the bookstore shopping site, which is the sub-front desk, the front desk used to display various types of book products, can be used to add shopping cart, can purchase the payment order, the backstage is used for books, book categories of additions and deletions, and the processing of orders. A not very complex project, but before the start of writing, it is not a clue, do not know, that is because there is no general understanding of the project, not knowing the level of the module, so not good from where to start to write code, and so will listen to me slowly, I will write my ideas and your ideas step-by-step to tell everyone , before, let's show you the effect.

Front Page

          

Before you log in, you can view all the book products, you can click on all categories, but also by category to find the corresponding category of books (12 items per page, with paging function)

           

And then register, where the use of Ajax to register the user name is verified, in order not to let duplicate names, and can send the activation code of the message to activate the account, inactive users are not logged on.

              

After login, add product to Cart

              

For their own orders to view (already have data in advance), some orders have not yet paid to make payment, payment has been waiting for the background click Delivery, sent the goods waiting for their own click to confirm the harvest.

                 

To pay for the order, select one of the banks will jump to which bank's page to make payment, as an experiment, will pay only one penny each time, pay is a test account. You can also apply for yourself, using the ePRO payment platform

                

The front desk is probably the case, now say backstage things, backstage is very simple. You can manage these goods.

Background Home

                

The features have been clearly written in the list on the left, to manage categories, books and orders, including additions and deletions. Here does not do too much introduction, the management of the order has a small logical management, you can pay the order of the delivery processing, then wait for the front-desk users click to confirm the harvest, confirm the harvest, it has been completed orders.

      

II. analysis of the project structure module

Just beginning to get the front shelf of this project, can only say, looks very simple several operations, also on the login, registration, view book information, add shopping cart, payment order, point to point to a few pages, but let oneself take up realize, really is not a little clue, but finished, will have a general understanding of the project, equivalent to the beginning of the 2D picture, now is the God perspective in the view of this project, a glance at the feeling. First of all, write about writing ideas.

The first thing is to understand the database design, clarify the relationship, and then understand the project needs to be divided into several modules. Understand the few, basically have a general understanding, you can write code to achieve.

2.1 Database design.

          

Five tables, now analyzed by one,

User table, which is used for login registration, to identify and manage users.

UID: A unique identifier that uses the UUID to obtain a 32-bit string that identifies the user.

Username: User name at logon, unique, cannot be duplicated.

Password: login password, and no encryption, it should be common sense to use encryption, so that the database to view the data can not see the original password.

Email: email to receive activation email

State: Whether the status ID is activated. 1 is active, 0 is inactive

Cdkey: Activation code.

In order to understand the Email,state,cdkey three fields, it is necessary to know the process of sending an activation code mail, first registration, state is 0, not activated, the registration will create an activation code, assuming that 123,cdkey=123, and then via email, User left the mailbox, send an activation email to the mailbox, the content is a hyperlink, the hyperlink will take two parameters, a parameter to hold the 123, a parameter to hold the UID, identify the user, click the hyperlink will jump to a processing activation of the servlet, will get the activation code parameter content with the database Cdkey contrast, see whether the same, the same, then for the activation, the use of UID to the user state to 1, if not the same, it is not the user click on the Activation Code mail came over, do not do processing.

  

Category table, categories of books classification table, such as fantasy, romance and so on. This table is relatively simple, see the project introduction above, you can know, the main page next to the category is the data from the table.

CID: A unique identifier that also uses the UUID to get a 32-bit string to act as the value

CNAME: Category name.

Book table, Books table, for storing all of the book information.

Bid: Unique identification code

Bname: Book Name

Price: Book prices, using the decimal type, reserved 2 for the decimal point. That is, the price is accurate to cent

Author: Book author

Image: A picture of a book, storing the path to a picture, rather than storing it in a database

CID: Refers to the CID field in the Category table, which is a foreign key field that identifies which category the book belongs to.

Isdel: Is this the state of the book, or is it under the shelf? This field is not used in the project I wrote, I did not write the logic code of this piece.

Analysis down, the Book table with the category table, each of the books will have an exclusive category, so that you can query the corresponding books by category, think of the front page by category to find the corresponding books to display, is through the relationship between the two tables to solve.

Orders table, order form

OID: Unique identification code

Total: The price, that is, there may be more than one item in the order, the overall price of multiple items

Ordertime: Time of order, type

State: The status of the order, there are four states, respectively, with 1,2,3,4 to identify, 1: Unpaid, 2: has been paid, to be shipped, 3: shipped, pending receipt, 4: Has received goods, orders completed,

Address: addresses, delivery must be an address.

UID: Point to the UID field in the user table, which is a foreign key field that identifies who the order is.

With the Orders table, the user table is connected, and by the time the foreground displays each user's own order, the UID field in the Orders table is queried for all of its orders.

OrderItem table, Order Item table, because there may be more than one item in an order, each item has to generate a orderitem record so that an order can be used to find out how many items are in the order.

Itemid: Unique identification code

Count: A purchase of a commodity, such as buy a This book bought two copies, because it is two book A, then there is no need to generate two OrderItem records.

Subtotal: What's the total price?

Bid: The bid for Book table, which is a foreign key field, that identifies which books the order item is

OID: A pointer to an OID in the Orders table, which is a foreign key field that identifies which order the order item belongs to.

The table links three tables together, Book table, Orders table, OrderItem table, user table. Their relationship should also be clear, a record in an Orders table is an order, whose order belongs to (through the UID field in the order), how many items in the order (through the OID field in the OrderItem table), the information for each item in the order ( Through the bid field in the OrderItem table). In fact, we are talking about a one-to-many correspondence, in which the foreign key field is stored in more than one side. They can analyze and analyze the relationship between these 5 tables, through who can find out who.

                  

2.2 Analyzing the foreground module

User Module

Login, register

Registered

Ajax Asynchronous Checksum user name

Send activation message

Activation complete

Login

Determine the user account password and whether it is active and save itself in session

Exit

Destroy session

Category Module

All categories are queried.

Display the category information in the first page, and take all the categories from the category table.

Library Module

Show all books, search for books according to category, search book details according to book ID.

By clicking on the category in the Category module, you will be able to show the books below that category. Click All categories, then all the books are displayed, here is the use of the Category table and Book table combined query, click on one of the books, will show the book details, and prompted the purchase of buttons, this button is to add their books to the shopping cart

       

Shopping Cart Module

Add to cart, remove items from your cart, empty your cart

Here is a map to act as a container for the shopping cart, using Linkedhashmap, the advantage is that access is fast, its principle is, to create a shopping cart item (cartitem) JavaBean, which has three properties, book object, has the purchase quantity acount,   There is also a total amount of Allmoney, using these three attributes to identify a commodity, and a shopping cart with a Map to act as a,map<string,cartitem>. String: The bid (the unique identifier of the book), the Cartitem is the shopping cart item to be loaded.

Add A book to the shopping Cart,

First, a book is encapsulated into a Cartiitem object, book property is all the information of a, acount on behalf of this added to the shopping cart a number of books, Allmoney represents the total amount,

After encapsulation into Cartitem, add it to cart (shopping cart, which is the map collection)

Determine if a book already exists in the cart by comparing it with all the key values in the cart by the unique ID of a book bid.

If there is a book, locate the Cartitem in the cart where key is bid, and modify acount and Allmoney in the Cartitem.

If a book does not exist, then a book is stored in the cart, with a book bid as the key value, with a book encapsulated Cartitem as value,

The cart (shopping cart, that is, the map collection) into the session scope, save the session scope, you can not permanently save the user's shopping cart, according to the session's characteristics, close the browser will be saved by default for 30 minutes, And if the cookie is not set in the browser to save, close the browser is lost Sessionid,session is not found, that is, the contents of the shopping cart is lost, so in the session is the characteristics I said, you can also save the shopping cart into the database, Then users can find their own shopping cart whenever they log in and where they log in.

Order Module

Generate orders, according to user inquiry order, according to order ID Inquiry order item, online payment function, modify order status

Add the item to the shopping cart, you can click to make payment, this time will jump to select the payment Method page, and generate the order, at this time the order state is 1, for the non-payment status, write the address, make payment, jump to the payment page, after the successful payment, will jump back to our own page, At this point the order state is 2. Called the paid on behalf of the shipment status, when the order is generated, also generates OrderItem (order items), that is, each item is generated order items. Its business operations are done at the service level.

2.3 Analysis Backend Module

Classification management to operate on the category table.

1, query classification, all the classification information to find out

2, add the classification,

3. Modify the classification

4. Delete Category

        

Book Management

1. Search for books

Find out all the book information

2. Add a book

File Upload (upload image information)

3. Modify Books

Modify a book picture or other information

4, book under the Shelf (delete)

        

Order Management

1. Check All status orders

2, check out the various status of the order (unpaid, paid hospitality delivery, has been shipped to confirm receipt, has confirmed the harvest order completed)

        

    

Third, the preparation process

3.1. Build the project Environment

Using the three-layer classic architecture, Web layer, service layer, DAO layer, if you want to use interface programming, then in the sub-interface class and implementation class.

The structure of my package

                

Add all the jar packages you need to use.

Mysql:1 a jar Package

C3P0 Connection pool: 1 jars

Dbutils Frame: 1 jars

File upload: 2 jar io and core jar (FileUpload)

Mail send: 1 jar javamail

Jsp:2 a jar,jstl and El expression (because using a JSP may require a custom label or other label, so bring it in in case you don't want it)

Beanutils:2 a jar beanutils and logging. (I don't use beanutils)

3.2. Write code

1, the development environment is set up, first will use the Dbutils framework will be connected to the database code to write well.

2, according to the above module to write, the first is the user module registration, login, from the JSP write to the servlet to the service layer to the DAO layer. Written in the order that it was written in the past.

3, the other is step by step, when the real start to write, everything will be able to follow their own ideas to go on, and not like the beginning, not start.

3.3. Note that

The servlet is written here using a reflection mechanism to reduce the number of servlets, and there are two ways to simplify the number of servlets.

The first kind.

Or in the old way, inheriting HttpServlet, overriding the Doget and Dopost methods, when sending a request, the servlet method that needs to be accessed is passed in the way of parameters, and then in the Serlvet the request parameter is determined to call which method, Write the method body under the servlet and invoke it within the Doget or Dopost method.

              

The second Kind

Reflection is used to load the corresponding method using reflection mechanism. There are three ways to understand the life cycle of the servlet, and it is important to know that the access servlet will go through the service method. Know all this is good to do, write a servlet passed, named Baseservlet.

            

Analysis: All methods are written in a new Servlet class, which inherits Baseservlet. When accessing the new Servlet class, because the service method needs to be executed, and the subclass does not, go to the parent class Baseservlet to find and execute, in the parent class will get the method name to execute, through the reflection mechanism, to execute the corresponding method in the subclass, Therefore, the methods and service that need to be executed can only be separated from the code, and all the logical code that needs to be written is in the subclass. Do not judge the method to choose the corresponding methods to perform, eliminating a lot of trouble, so that the code more concise, easy to understand.

Iv. Summary

Through this project, the three layer of the classic architecture to understand more deeply, and for the web of large and small knowledge points are consolidated, JSP four scopes, 9 large built-in objects, the use of El expression, send mail, online payment links and many other knowledge, and through the servlet+jsp+ The schema of the database is indeed more complex, thus knowing the benefits of using the framework for ease of development.

Now give the project source code, hope to help you.

      

Http://pan.baidu.com/s/1i4W79BZ 67me

     

       

            

      

  

Java Web (14) write a summary of the Mybookstore project

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.