0. Write in front
Friendly tips: The download address is below.
The project has been basically completed. With this summary, I have written 30 blogs related to this project, which have accumulated a lot. The process of writing a blog is a process of solidifying ideas. It is very useful to myself and can also help others. By the way, there will definitely be many exceptions in the process of learning. The first thing we need to do is to locate this exception. Generally, one or more Caused by: xxx are followed by the exception. These are the causes of the exception. Generally, we look for the Caused by the bottom, which is often the root of the problem. If you can't solve it yourself, you can search on Google or Baidu (don't post a lot of abnormalities when searching, pay attention to the key parts!). Generally, 99.9% of the problems we encounter have encountered have been encountered by our predecessors, and basically all of them can be solved. I basically do this when I encounter problems that cannot be solved. If I solve them more myself, I will feel it~ Finally, I hope everyone will gain something when reading my blog!
I won’t say nonsense. Let’s summarize the project of this online mall below. I won’t cover everything. It is mainly divided into several modules to summarize, including which technologies are used, etc. I will attach a quick link to the specific details in the article. You can check out a specific article.
Recalling this project, it can be divided into these main modules:
---Building of project environment
---Build a backend management system
---Build a front desk display page
--- Shopping cart related functions
---Online payment function
---Send email and text messages
---Domain name application and project deployment
---Form verification and report display
The following is a specific analysis for each module.
1. Construction of the project environment
This is an indispensable link in every project, and there will be many messy problems. When I first started learning SSH, I always struggled to build the environment because I was not very skilled, but I just wanted to build it "rhythmically". That is to say, building an environmental project requires step by step, bit by bit. Many people will import all the jar packages into it, and then write all the configuration files or paste them from other places, and then run them, and then hang them... and then find various problems. Why bother? In this way, even if you build it 10 times, you won’t be able to do it easily. You have to eat rice in one bite, and you have to walk step by step.
The process I personally follow for SSH environment construction is:
Spring > Hibernate > Spring Integration Hibernate > Struts2 > Spring Integration Struts2
After each step, write a test test. This is very important, because if you go step by step, you will know where to go if you make a mistake and where to find the problem. The most important thing is that if you become proficient in this process, it will be easy to get the environment next time. For more information about SSH environment construction, please see the following article:
Integrate Struts2, Hibernate4.3 and Spring4.2
Basic addition, deletion, search and modification, extraction of Service and Action, and replacing xml with annotations
2. Build a backend management system
I use EasyUI to build the backend management system. To be honest, I have only a little understanding of EasyUI. I don’t know much about the front-end things, but I understand a little bit. I also checked them all when I use them. I have not learned them systematically, so I don’t have a good knowledge system, but it doesn’t affect playing. Programmers like to say that they are playing a technology, and they sound quite high-end. I have gradually been affected and I like to say that, but I am really playing with the front-end...
jQuery EasyUI is a collection of UI plug-ins based on jQuery, and the goal of jQuery EasyUI is to help web developers create a UI interface that is rich in features and beautifully. Developers do not need to write complex JavaScript, nor do they need to have an in-depth understanding of CSS styles. All developers need to know is some simple HTML tags.
EasyUI requests are all Ajax requests, and no new pages will appear, they are all in the tab tab or a window pops up. The backend management system is mainly divided into three parts: product category management, product management and sales management. Sales management is last.
2.1 Product category management
This part mainly involves the construction of EasyUI environment and background framework, cascading query and pagination of databases, DataGrid data display, Struts2 integration json, and product categories addition, deletion, update and search. This also follows a sequence of completions in this section.
DataGrid displays data in the form of a table, and developers do not need to have specific knowledge to operate it. It has a good help document and is more detailed. In this project, I have also introduced several ways to create DataGrid, and also briefly introduced some of the properties of DataGrid. It is a beginning. I am also an introductory tool. Only by developing more can I master this technology.
The categories' addition, deletion, update and search functions mainly use the verification function that comes with EasyUI. When adding product categories, verify whether the input in the input box is correct, whether it is required, etc.; whether a certain line or several lines are selected first when deleting; when updating, only one line can be updated at a time, etc., all of which are Ajax requests.
For more information about this part, I have already classified it, please refer to these articles:
Use EasyUI to build a backend page framework. EasyUI menu to implement cascading query and pagination of databases. DataGrid data display function Struts2 and Json integrated DataGrid to implement query and delete function DataGrid to implement addition and update function DataGrid to implement addition and update function
Here are the problems I encountered:
Lazy loading exception problem in Struts2 and Json integration Hibernate4 execution save() or update() is invalid
2.2 Product management
Product management also includes operations such as adding and deleting, which is the same as category management. There is one thing that adds products and needs to upload photos of products. This involves the function of Struts2 to implement file uploads. We need to build a folder on the server side to store uploaded files, and then write a model to receive files. Regarding file upload, we need to write a tool class specifically. This is how the development in the project is. Common code must be extracted, even if there is only one sentence of code, it must be extracted! This is a habit and must be done. For specific details, please refer to the articles listed below:
The basic module of the product category is built and query and delete product function is implemented. The implementation of the product function is implemented. The implementation of the file upload function is implemented.
3. Build a front desk display page
Of course, the front-end page was not designed by me. I summarized some back-end technologies related to front-end display, such as: the listener obtains home page data, the timer synchronizes home page data, and the Hibernate level 2 cache processing cache of popular products.
When I was learning servlet, this is how I did the home page display data. I used a frame and displayed the data on the right. Then I jumped to a servlet on the right part in index.jsp, and then went to the servlet to take out all the products from the database, put them in the request field and brought the new jsp page to display. Although this can be achieved, it is very stupid. Here I used a listener to do this. First, I defined a listener myself, and when the project started, I took out all the product information in the database, put it in the application domain, and then directly used EL expressions to retrieve it from the application domain in the homepage.
There is another problem. When I add a new product to the management system, I have to restart tomcat to add the new product to the application domain. Because it has been in the application domain after the first time I took it out, it is determined to die. The newly added later is not in the application domain. In order to solve this problem, I used a timer to synchronize the homepage data. So I rewritten the listener I wrote before, set a timer in the listener, put the code to obtain the data of the product in the database into the timer task, and execute it immediately for the first time, and then execute it every 6 hours (the time can be set at will by yourself), that is, re-acquire the products in the database every 6 hours and save it in the application domain. This is what the general website does, like CSDN’s personal blog homepage, the ranking is updated every day, probably around 10 pm, I forgot the specific time. At that time, the refresh will see the data update, which will also reduce the pressure on the server.
For specific technical details in this section, please refer to the following articles:
Use the listener to get the data displayed on the home page. How to get the Spring configuration file thread, timer timing synchronization home page data Hibernate secondary cache processing home page popular display
4. Shopping cart related functions
The main technologies involved in the shopping cart include: the background processing of the logic of shopping carts and shopping items, filter judgment login, cascading orders into the database, and page caching.
For shopping carts, it mainly contains some implementation logic in the backend. There are shopping items in the shopping cart. What does it mean? We all know that when we buy things on Tmall, we can put different products in the shopping cart, and then there are many products in the shopping cart, and each product can have multiple quantities. Each product and its related information is a shopping item. Therefore, when adding a shopping cart, we must first complete a shopping item and then add this shopping item to the shopping cart.
When a user wants to settle, we must first determine whether the user has logged in. This uses filter technology, which specifically filters a certain type of url, and determines whether there is a user object in the current session in the filter. If there is any indication that login has been logged in, just release it directly. If not, jump to the login page to let the user login. After logging in, jump to the page the user originally wanted. It's like a doorman~ looking at the door~
As mentioned just now, the order information includes shopping carts and shopping items. When we enter the orders, we must consider their cascading issues. We can set the corresponding annotation attributes in the POJOs of the two. However, there is a prerequisite. For example, if there is a foreign key correlation, the fields in the foreign key part of the corresponding POJO must be assigned a good value before entering the POJO. For example, the order must be added to the line item, and the order attributes in the line item must also be assigned a good value before they can be handed over to Hibernate. Hibernate cascades them into the library according to the configured annotations (or xml file).
The problem with page caching refers to that when the user confirms the order, if he clicks back, he will return to the order confirmation page. The order confirmation page just now comes out again, and the session is still there, and the information is still the information just now. This is obviously not the result we want. We need to process it in the front desk and backend at the same time.
Please refer to the following articles for specific technical details in this section:
Implementation of basic functions of shopping cart filter to realize login function to determine cascading storage and page caching issues of order information
5. Online payment function
This part mainly introduces some things about Yibao payment interface. In fact, online payment functions are different for different third parties. The main purpose is to understand a process of online payment function development. The specific technical details depend on the information provided by the specific third parties. But the general process is: calling the third party's interface > calling the bank interface > completing payment > The third party jumps back to the page we specified.
This part also involves an important technology, which is how struts2 handles multiple model requests. Generally, struts2 can use the model in Action after implementing ModeDriven<model>, but what if there are two models now? There is another interface called parametersAware in struts2. As long as this interface is implemented and a map that stores parameters is defined, it can receive all parameters in the request request. We can judge which model to use based on different parameters. This method can solve the problem of struts2 handling multiple model requests.
For technical details in this section, please refer to the following blog post:
An introduction to the online payment platform, a demo of Yibao payment process
Get the display of bank icons and payment pages to complete the logic of online payment function How to handle multiple model requests in struts2
6. Email and SMS Send Function
The sending of emails and sending text messages is relatively simple. They are both fixed APIs, just know how to use them. Just check them, and I can't remember them either. The email sending function needs to import the mail.jar package, and then send emails according to the process. The SMS function must first apply for the SMS sending function. After the application is completed, the third party will provide us with some API interfaces. We can develop the SMS sending function as long as we refer to it. It is somewhat similar to the payment function, and they all rely on third-party platforms.
There are no technical difficulties in this part, mainly the process, the related articles are as follows:
Send SMS function after successful order payment is completed using java email to users
7. Application for domain namespace and deployment and release of projects
This section mainly introduces how to apply for a free domain name space (free for 15 days only~ but for learning, enough~). Although not all of them are free, we mainly need to figure out this process. It is better to go through it yourself. It does not necessarily have to upload a complete project. A jsp page or html static page is fine.
There are two main ways to deploy and publish a project: one is to upload using FTP, but this is slow and may lose data. Personal experience is to issue it bit by bit; another way is to apply for a domain name space to provide a deployment environment. We just need to export the project as a war package and then deploy the war package.
There are many details to pay attention to before the project is deployed, such as modifying some paths, modifying some data, etc. These details are explained in detail in my blog. This section contains one article, as follows:
Application for domain name space and deployment and release of project
8. Form verification and report display
Some things are added later, which are Ajax dynamically updates the quantity of products in the shopping cart, the verification of forms and the display of reports.
The number of products in the shopping cart dynamic update is pure Ajax technology. I just learned it. The verification of the form is mainly the login form. I did not login in this project, but I made a login form and the verification function is also done. The main use is the Validate verification plug-in of jQuery. This plug-in is still very powerful. You can directly add the login form to the project and set the corresponding jump. The main use of JsChart for the display of reports is JsChart. This tool is very useful and can generate response js code. What we need to do is to send Ajax requests to the backend, retrieve data from the backend according to actual needs, and pass it to the frontend to display it with JsChart chart.
I will list the blog posts in this section below:
Use Ajax technology to partially update product quantity and total price jQuery-Validate verification plug-in to display product sales reports in the background using JsChart technology
This is the online mall project that has written so much. The source code in the CSDN download channel is synchronized with my blog. If you need it, you can download the source code I uploaded in CSDN (free ~ all my resources are free). If I want to continue to improve it later, I will put it in my github. Everyone is also welcome to follow my github (although it is average~) Star project I uploaded~ The following is the specific download address:
Download address (synchronize with blog content)
GitHub download address (if there is an update later, it will be placed here)
Original address: http://blog.csdn.net/eson_15/article/details/51479994#download
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.