E-commerce project introduction

Developed in Shenzhen for two years. I have participated in the development of three projects, one is the internal management system of a hospital, the other is e-commerce, and recently I have done an e-commerce project. The previous project was built using the ssh framework, and the most recent project was built using the ssm framework. In actual development, I think the biggest difference between these two frameworks is the difference between hibernate and mybatis. Compared with Hibernate and mybatis, mybatis is lighter, more flexible and easier to master. Mybatis can separate sql statements from Java code and write them in configuration files, which greatly reduces the coupling between java code and SQL statements, making it easier to operate sql statements. The important thing is that mybatis can also write dynamic sql statement, but mybatis also has some defects. For example, the caching mechanism of mybatis itself is not as perfect as that of hibernate. In addition to its own good caching mechanism, hibernate can also use third-party caching. Hibernate encapsulates JDBC more completely, but it is more difficult to learn than mybatis. Hibernate's DAO layer development is simpler than MyBatis, and the maintenance and caching of objects is better than MyBatis.

(The difference between springmvc and Struts: springmvc is a method-level interception, a method corresponds to a request context, and a method corresponds to a url at the same time, and the transfer of parameters is directly injected into the method, which is unique to this method.

Struts2 is a class-level interception. A class corresponds to a request context. When struts accepts parameters, it can use attributes to accept parameters, which means that parameters are shared by multiple methods, which means that annotations or other methods cannot be used. identifies the method to which it belongs).

The mall is a comprehensive B2B platform, mainly targeting pharmaceutical pharmacies. Products cover tonics, nutritional health products, Chinese and Western medicines, medical equipment and other related products.

In the whole project, we use nginx+tomcat to deploy (the interviewer may ask who deployed nginx? How to deploy? Nginx execution process, advantages),

On the one hand, nginx acts as a server for loading static resources, and on the other hand, it acts as a reverse proxy and load balancing. Because the project needs to run in multiple environments, we use the reverse proxy of nginx to solve the problem caused by the inconsistent access addresses of different environments and systems.

 

Because the whole project implements many functions, it adopts a distributed architecture design. The whole project includes a background management system, a foreground system, an order system, a login system, a search system, a shopping cart system, etc. The advantage of this is that each function The modules are independent, which reduces the coupling between the various systems, and adding or deleting a function will not affect other functional modules.

Because the project is designed with a distributed architecture, each module is independent of each other, and the access paths of each module are different, so when requesting data across domains, it will be subject to cross domain restrictions. For example, when a user visits the homepage of the website for the first time. The home page will asynchronously request the number of products in the background management system. This is the problem of cross-domain restrictions. In the previous development, if in this module, we requested data asynchronously through Ajax, but Ajax cross-domain is not supported. The feature that Jsonp can request cross-domain through the src of the script tag. Load the resource, parse the loaded resource (package a data with a method name) as a js script, and define a callback function. (How it is implemented) Get incoming data. We use jsonp because jsonp is more compatible. And after the request is completed, the result is returned by callback. But Jsonp has a disadvantage that it only supports get requests and not other types of http such as post.

In this way, we solve the cross-domain problem that the browser accesses the current page to load background data. But another problem arises. How do other systems call the data of the background system? We want to be able to send http requests to access background data. What we came up with is httpclient to solve this problem. Because httpClient can use java code to simulate the browser to send http requests (how does the get method pass parameters? Define the uribuilder object, set the parameters in the uribuilder, the key and value are all string types, and then put the uribuilder in the uri, and then Tell the uri to the httpget request. If the Post method transmits data? Simulate form submission, encapsulate the data into the list collection, then put the collection data into the constructed form entity, and put the form entity request into the httppost object) outward Throwing an interface, the execution process is: 1. Create the httpClient object, 2. Construct the request POST, get request, 3. If there are parameters, go to construct the parameters.

     3.1 get

       Use uribuilder to construct request parameters

       3.2 post

        Build the form entity and put the form entity into the post request object.

4. Execute the request and accept the response

5. Process the response result

6. Release the connection. The connection must be released regardless of the success of executing the method.

The HttpClient implementation is considered thread safe.

Every time a connection initiates an Http request, the connection will be re-established (after 3 handshakes), and the connection will be closed (4 waves of hands) when it is used up, which will consume a lot of time, so we use connection pooling. If the connection pool is not used, a port will be opened for each connection. In the case of large concurrency, the port resources of the system will be quickly used up, resulting in the inability to establish a new connection.

Data such as large advertisements and commodity categories on the homepage of the project do not need to be modified frequently. If the user has to query from the database every time the page is refreshed, it will waste resources and increase the pressure on the database. So we want to add this data to a buffer. At present, the more mainstream caching technologies are Redis and Memcached. From the perspective of cache hits, Memcached is higher , but the gap between redis and Memcache is not large, but the functions provided by Redis are more powerful, and the read and write speed is also very fast. quick. So we chose redis to cache data. Redis caches data in the memory in the form of key-value, and provides a variety of data storage types (string, set, list, hash, etc.), and also provides its own persistence function (2 types), and can also back up data to disk (Redis's SAVE command is used to create a backup of the current Redis database) to prevent data loss when redis is down. (The updated data is periodically written to the disk or the modification operation is written to the appended record file, and master-slave (master-slave) synchronization is realized on this basis). We use a client that integrates spring and jedis, and we can use jedis as a sharded cluster to solve the problem of limited memory in redis.

Previously, login and registration were implemented within a tomcat. The current system architecture is that each system is maintained by a team, and each system is deployed separately to run a separate tomcat, so the user's login information cannot be saved in the session (multiple tomcat sessions It cannot be shared) (session sharing?), so we need an independent system to maintain user login information. This is what we do. The user goes to the login page to log in, and goes to the database to query whether the user exists. If there is no user prompting the user, if there is user information saved in redis, and the generated token is saved in the cookie.

In the background management system, maven multi-module development is used. Among them, the method of horizontal segmentation (the difference between vertical and horizontal division: vertical: functional modules are clear, the level is not clear enough, code reusability check, horizontal: clear level, code reuse, independent maintenance) to develop each layer in layers , the advantages of doing so are high code reuse, clear levels, and easy independent maintenance. The internal interface call of the system adopts httpClient, and the interface adopts the interface definition of RESTful style (a software architecture style, the design style is not the standard. It just provides a set of design principles and constraints). The notification mechanism between systems adopts the MQ method, uses the implementation of RabbitMQ, and uses the message mechanism of RabbitMQ's message subscription mode. In terms of deployment, the Nginx+tomcat mode is adopted. The role of nginx is to be a reverse proxy, Load balancing, on the other hand, is a server for static resources such as pictures;

In this project I am mainly responsible for the backend module. Mainly realize commodity management and commodity specification parameter management. CRUD operations on items and item specifications. When implementing the foreground call data, in order to realize the call between systems. The httpclient technology is used to realize this function, and the interface that needs to be called is provided in the background. (httpclient introduction, working principle, advantages and disadvantages). If the product is operated in the background. In order to synchronize the front-end and back-end data, we use the RabbitMQ message queue mechanism to realize the commodity synchronization function (RabbitMQ introduction, working principle, advantages and disadvantages);

In this project, I also participated in the development of the shopping cart module. When developing this module, I also considered how to save product information in the background when members add products to the shopping cart without logging in and logging in.

When the user clicks to add to the shopping cart on the user details page, we use a login interceptor to determine whether the user is logged in. If not, the product information is saved in a cookie. When the user logs in, the product is persisted to the database, but Consider the issue of cookie storage size. Also, when the cookie stores more data, it will affect the response speed. We decided to use redis to cache the product information of users when they are not logged in (the principle, introduction, advantages and disadvantages of redis) and design the cache lifetime in redis (how to do it), if the user does not log in within the specified time, the data Change back to automatic deletion. If the user logs in at the specified time, the RabbitMQ message queue mechanism will be used to synchronize the data to the database.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324896239&siteId=291194637