Shopping cart, generate orders

Copyright: https://blog.csdn.net/qq_39263750/article/details/90021895

After adding the order ID how to get the current orders?

plan 1:
Here Insert Picture Description

The problem with this scheme is that the system does not use the same person, in the case of multiple concurrent, if you add orders while others also get the order, then this MaxId do not know who it is.

Scenario 2:
Here Insert Picture Description
Here Insert Picture Description
This sentence is to tell the database, during the execution of the statement added, to get to his master key.
Here Insert Picture Description
To get the result set, but this would only return the id of the Orders table (one or more, depending on the number you add to a given)

Test: Add an order is necessary to add the current location of the order, this order also need to join to create a user id

Here Insert Picture Description

A business: Order timeout, merchandise inventory increase / decrease of cases

: After the order generation will have a status: unpaid. Since the stock will be reduced after the order, the state has not paid not exist.
So in order to be added to create aTimerAfter time out after a fixed period of time, the inventory re-applied to the (automatic recovery).

Timer Task achieved in two ways:
first: java.util.Timer tool to complete the operation timing of
a second: open frame, the scheduler Quartz

The same point two methods:
the timing to perform some tasks, time to remove some outdated data. Timing send some notifications.

Difference: Quartz open source framework, more comprehensive and powerful, but complicated to use.

Timer is jdk own tools, easy and simple learning curve, better able to complete timed tasks.

Here Insert Picture Description
Here Insert Picture Description

Test
Here Insert Picture Description
Here Insert Picture Description
is performed only once.

Here Insert Picture Description
Then we meet the multi-threaded, and run multiple timers simultaneously.
Here Insert Picture Description

Question: After the timer is finished now, and did not close the timer, but hung consume memory. So I want to close.

Off Timer:
Here Insert Picture Description

But this can not be directly written inside, java statement execution order, here to write directly off

Util requires written inside,
Here Insert Picture Description

Then timerTask which calls on the line.
Here Insert Picture Description

This time found that the timer is over, the process automatically closed.

Then there is the problem of recovery of the commodity stocks:

shopping cart

Complete cart can be used in three ways:
the session is done: save everyone's cart in a cookie
save the cart off the personal data in a cookie: Use cookie to complete.
Uses a database: the data stored in the database. (Because the cart will be frequent additions and deletions, complete with database efficiency is low.)

Why session:

1. The cart data change frequently. (Number of changes)

In order to better optimize the session, only the == id of goods inside the shopping cart of the current session == presence inside.
(If nothing exist, more and more users, session accounting for more and more memory is needed.)

Write a method to query the other data based on the ID in the business layer.
The argument is a passset(Because it may come to pass multiple id, the shopping cart is not the only commodity) id inside are filled with goods.
return entity objects from all commodities.Here Insert Picture Description

map the key is just to put a set id wear into.

When the query returns another pass into a collection that contains all the properties of the product list.

About BookDto
Here Insert Picture Description

Reception:
Here Insert Picture Description
click send ajax request.
Here Insert Picture Description

Additional information can be hidden in hidden inside pass over
calls addcar the id of the current commodities pass in the past;
Here Insert Picture Description
Here Insert Picture Description

To get id (with no controller, id can pass directly over 0

Get the session object

Create a map

If sql too, affect the efficiency
by stitching StringBuffer get on? Numbers and commas
Here Insert Picture Description

Business layer: Design findBookByI return dto

Persistence Layer Design

test

Write controller

Guess you like

Origin blog.csdn.net/qq_39263750/article/details/90021895