Goal:
L MASTER the information how to store the shopping cart;
L MASTER The realization of the common function of shopping cart.
main content:
L First analyzes the general process of user online shopping;
L Describes what data structure is used to store shopping information;
L Write shopping interface;
L completes the function of adding items to the shopping cart.
1, the general process of user online shopping
If you are interested in an item in the process of browsing the item,
will be added to the shopping cart (shopping basket), you can always view the information in the cart, if you do not want an item, you can delete, or modify the number of items, or the entire empty cart, you can continue to select items to add to the cart. Finally, users can purchase these items, after entering personal shipping address information and set up trading methods, you can generate orders. The administrator of the Web site can manage orders.
This example simulates this process, but simplifies it: only select items in the list of items to add to the cart. Make sure that you do not need to set up trading methods and payments after purchasing. The actual processing process can be done using the features we described earlier.
2, Shopping cart information organization
Because shopping cart information can be accessed throughout the course of a user's visit to the site, the shopping Cart object should be stored in session.
Because the user buys the item the kind and the quantity is uncertain, therefore needs to use a suitable data structure storage, we choose ArrayList.
Each item is involved in quantity, it needs to be encapsulated, the item and quantity are packaged into a shopping item, the item is used, each item corresponds to an item and the quantity of the item.
need to write an item class that represents the basic information of an item.
Reference code is as follows:
2.1 Goods class
This class contains two methods that are related to paging display. The Dbbean used is described earlier.
package JavaBean;
import java.util.ArrayList;
import java.sql.*;
public class goods
{
private String goodsid;
private String goodsname;
Private float price;
//Item number
public void Setgoodsid (String goodsid)
{
this.goodsid = goodsid;
}
public String getgoodsid ()
{
return Goodsid;
}
//Item name
public void Setgoodsname (String goodsname)
{
this.goodsname = goodsname;
}
Public String getgoodsname ()
{
return goodsname;
}