Today is the 113th day for Liu Xiaoai to learn Java by herself.

Thank you for watching. Thank you.

Without further ado, let’s begin today’s lesson:


Project one will be over after today.

Tomorrow I will start to learn SSM framework, and then use SSM framework to optimize this small project as an exercise.

I think the framework is a watershed, so I decided to make an ideological reflection on the previous period of learning, and finish the task in the weekend. Today’s arrangement is as follows:

  • First of yesterday’s collection of business code correction, some of the mistakes made by their own summary.

  • Then learn about the use of transactions in a project.

  • One last bit of gossip.

First, some mistakes I made

Some because they do not understand the use, only know rote memorization, take it for granted to write code.

Some are just plain stupid mistakes.

1 the use of jdbctemplate


On the difference between query operations and add, delete, modify operations.

Add, delete and change operations do not need mapper, and this error occurred several times during yesterday’s code writing.

I thought about the reason and found that I had mixed up ① and ③.

① Is a modification operation, the return value is int.

But it’s not a result of a query from the database, it’s just a number to determine whether the modification succeeded or failed.

Although I don’t know why it doesn’t use a Boolean.

③ Is a query operation, the return value is also an int.

But it is a result from a query in the database, the above is the total number of statistics, so you need a mapper.

2 The front-end fails to obtain JSON data


This is a mistake I’ve made several times, where the server responds with success and the data is visible on the browser console.

But using result does not fetch the data.

Later, I realized that there was a problem with the front-end JSON parameter.

When you can’t get json data, it’s usually because you forgot to write it, or you wrote it in the wrong place.

3 the selector


This is, needless to say, a low-level error, the ID selector format problem.

It must have set an ID for the corresponding tag, and then copied it directly, without noticing the formatting problem.

Second, business management

In favorites, there is business logic like this:

  • User click favorites, favorites table to add a data.
  • At the same time, the number of collections in the commodity list should be increased by one.

There was a problem with yesterday’s code: bookmark succeeded, bookmark table added a data.

However, it failed to increase the number of collections in the item list, and the total number of collections did not increase.

According to our business requirements, this is obviously not possible, both functions will either succeed or fail at the same time.

Using transactions in a database solves this problem:


1. Start the transaction manager

Don’t look at the huge length of the code, which is actually made up of a few common words:

  • A Transaction
  • “Synchronization” : Synchronization or lock
  • Manager: That’s right
  • Init: indicates initialization

The current transaction initializes a lock that is bound to the thread.

② Start transaction

Transactions are committed automatically by default, so we’re going to commit manually, so set transaction commit to false.

The template is then passed as a parameter to the business to bind, thus passing them to the bound transaction.

③ Transaction commit and rollback

If no error is reported and the transaction commits, call commit.

If an error occurs, the transaction is rolled back and the rollback method is called.

④ After the service is executed

Unlocks the current thread and the connection.


In the DAO layer, the database is queried using parameters from the Service layer, which are local variables.

We all know that local variables are preferred when global variables have the same name as local variables.

Three, gossip

In this small project, I skipped some business and left unfinished, such as the realization of paging function of favorites module.

Because I have spent the last three days studying paging in the goods module, they are implemented the same way.

And I heard that this way is very low, there are plug-ins can be directly used, I thought about it and directly skipped.

I did some research on the Internet and there is indeed a pagination plugin called Layui that is said to be quite useful.


I’ve also skipped over project deployment, so I’ll come back to project 2 and Project 3.

The main reason is that I am curious about the study of the frame. Every day someone tells me how to use the frame and how to use it.

I can’t wait to find out.

Fortunately, I no longer grind, directly began to framework learning, spring family bucket, HERE I come!

The last

Thanks for watching.

If you can, please give it a thumbs up. Thank you.