As part of the project responsible for the school's library in the next semester, I now encounter a business design difficulty.
For example, on the homepage, I plan to use ajax to load all the information when students query related information. I am not used to many websites such as Zhihu that drag to the bottom to load automatically. My idea is to set up a paging option at the bottom, display 15 records on each page, and load all articles using ajax.
The sql statement is probablyselect xxx from xxx condition limit 15 offset xxx
. But now because I want to do paging, I must know how many records a student has in the database in order to design the front end. The total records can be queried through the SQL statementselect count(*) from xxx condition
. The total records are then saved in the frontend.
If this is the case, the query must be split into two sql statements, which does not feel very elegant. Is there any more elegant implementation plan?
ps: Because there are many similar businesses in the system that require similar paging designs, it is too inelegant to use two SQL statements to query separately every time.
Replenish
The respondentseems thatdidn’t even read the question. One person answered about sql statement 1, and the other person talked about the front end.
Thank you all for your answers. The problem has been solved. It seems that only two sql statements can be used ^_^
Don’t think about it, it must be two.
You can also have one:
select * from table
union
select 0, 0...., count(*) from table
This is normal.If you want to use a SQL to solve the problem, you have to check all the objects from the database and perform a series of operations, but your memory may explode.
Don’t think about it, it must be two. The implementation of paging defines a generic class page and what is put in it. Do you need me to explain in more detail?
Try PageHelper, it’s just a sql statement, you don’t even need a limit
For elegant paging, there are many plugins for paging