search

Home  >  Q&A  >  body text

java - What is a more elegant way to implement paging loading in business?

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 probably select 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 statement select 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 respondent seems that didn’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 ^_^

阿神阿神2772 days ago693

reply all(6)I'll reply

  • 大家讲道理

    大家讲道理2017-06-06 09:53:51

    var start = 页标 - 1;
    $.get("url?start=" + start * 15,function(){});
    $start = $_GET["start"];
    $end = $start + 15;
    $sql = "select * from table limit {$start}, {$end}"; 
    select a.*, b.count from table a, (select count(*) as count from table ) b LIMIT 1,15

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-06-06 09:53:51

    Don’t think about it, it must be two.
    You can also have one:
    select * from table
    union
    select 0, 0...., count(*) from table

    reply
    0
  • 怪我咯

    怪我咯2017-06-06 09:53:51

    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.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-06 09:53:51

    Don’t think about it, it must be two. The implementation of paging defines a generic class page<T> and what is put in it. Do you need me to explain in more detail?

    reply
    0
  • 習慣沉默

    習慣沉默2017-06-06 09:53:51

    Try PageHelper, it’s just a sql statement, you don’t even need a limit

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-06 09:53:51

    For elegant paging, there are many plugins for paging

    reply
    0
  • Cancelreply