Chapter 13 design of Chuanzhi Book City Project

1, Project overview

In recent years, with the rapid rise of the Internet, the Internet has become the best channel to collect information and gradually entered the traditional circulation field. Therefore, e-commerce has become popular. More and more businesses have built online stores to show consumers a novel shopping concept. As the front-end business platform of B2B, B2C (Business to Customer) and C2C (Customer to Customer), online shopping system plays an important role in the whole process of its business activities. In the project of Chuanzhi book city, it mainly explains how to build a B2C online shopping system.

The project of Chuanzhi book city is divided into two parts: front desk and back desk. The functional structure of the front desk is shown in the figure below.

The functional structure of the background part is shown in the figure below:


2, Database design

Before designing the database, it is necessary to clarify which entity objects are in the Chuanzhi book city project. The database is designed according to the relationship between entity objects. Next, we introduce a model that can describe the relationship between entities and objects - E-R diagram. E-R diagram, also known as entity relationship diagram, can intuitively represent the relationship between entity types and attributes.

E-R diagram of user entity.

E-R diagram of commodity entities (products).

E-R diagram of order entities.
E-R diagram of order item.

E-R diagram of notice.

3, Project environment construction

3.1. Determine the project development environment
operating system

web server

JDK version

database

development tool

Browser version

3.2. Create database tables

3.3. Create project and introduce JAR package

The project name is itcaststore, the type is Dynamic Web Project 2.5, and the required jar packages are as follows:

3.4. Configure c3p0 config xml

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
	<default-config>
		<property name="driverClass">com.mysql.jdbc.Driver</property>
		<property name="jdbcUrl">jdbc:mysql:///itcaststore</property>
		<property name="user">root</property>
		<property name="password">root</property>
	</default-config> 
</c3p0-config> 

3.5. Coding filter

/**
 * Coding filter (used to unify project coding)
 */
public class EncodingFilter implements Filter {
	public void init(FilterConfig filterConfig) throws ServletException {
 
	}
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// Processing request garbled		
		request.setCharacterEncoding("utf-8");
		// Processing response garbled code
		response.setContentType("text/html;charset=utf-8");
		chain.doFilter(request, response);
	}
	public void destroy() {
 
	}
}

3.6. Write tool class DataSourceUtils

/**
 * Data source tools
 */
public class DataSourceUtils {
	private static DataSource dataSource = new ComboPooledDataSource();
	private static ThreadLocal<Connection> tl = new ThreadLocal<Connection>();
 
	public static DataSource getDataSource() {
		return dataSource;
	}
	/**
	 * When DBUtils needs to manually control the transaction, call this method to obtain a connection
	 * @return
	 * @throws SQLException
	 */
	public static Connection getConnection() throws SQLException {
		Connection con = tl.get();
		if (con == null) {
			con = dataSource.getConnection();
			tl.set(con);
		}
		return con;
	}
	/**
	 * Open transaction
	 * @throws SQLException
	 */
	public static void startTransaction() throws SQLException {
		Connection con = getConnection();
		if (con != null)
			con.setAutoCommit(false);
	}
	/**
	 * Release and close the Connection from ThreadLocal and end the transaction
	 * @throws SQLException
	 */
	public static void releaseAndCloseConnection() throws SQLException {
		Connection con = getConnection();
		if (con != null) {
			con.commit();
			tl.remove();
			con.close();
		}
	}
	/**
	 * Transaction rollback
	 * @throws SQLException 
	 */
	public static void rollback() throws SQLException {
		Connection con = getConnection();
		if (con != null) {
			con.rollback();
		}
	}
}

Keywords: Java Eclipse

Added by Reaper0167 on Tue, 04 Jan 2022 14:02:31 +0200