Paging logic implementation

Paging Profile

For dividing data into a plurality of sub-page display in part.

When to use?

The amount of data reaches a certain time, you need to use the paging for data segmentation. Or else you may face the following problems:

  • Client data is displayed at once too much will affect the user experience, such as difficult to find information that customers want, and loads the page data is too slow.
  • For the server, the data is delivered once too much, it may cause memory overflow.

Classified pagination

Paging Paging is divided into true and false page:

  • True page (physical page):
    Use in mysql select * from table where ... limit start, size ( in some complex oracle)
    The first parameter represents the start position start index data
    second parameter is the number of data to be queried
  • False tab (logical page):
    directly select * from table where ...
    so that all data out of the query stored in memory, to fetch each time interval corresponding index data when need, directly from memory

the difference

Compared to the fake page really does not cause paged memory overflow, but slow compared to the fake page page of data, according to the actual situation, select the sort mode, if the amount of data, consider using fake pages faster page turning .

achieve

Fake page

False paging List actually used to store the value of all queries to retrieve data between two indices then subList method.

First in the dao layer interfaces create StudentMapper

List<Student> queryStudentsByArray();

StudentMapper.xml then create a file, write the query:

<select id="queryStudentsByArray" resultType="Student">
   select * from student
</select>

Service interface and then define custom paging methods:

List<Student> queryStudentsByArray(int currPage, int pageSize);

Rewrite the method Servlce implementation class:

@Override
public List<Student> queryStudentsByArray(int currPage, int pageSize) {
     List<Student> students = studentMapper.queryStudentsByArray();
     // 从第几条数据开始
     int firstIndex = (currPage - 1) * pageSize;
     // 到第几条数据结束
     int lastIndex = currPage * pageSize;
     return students.subList(firstIndex, lastIndex);
}

Here the controller and the front desk will be prepared in accordance with this method.

True Page

Temporarily to not finishing.

Published 14 original articles · won praise 15 · views 521

Guess you like

Origin blog.csdn.net/CodingNO1/article/details/104423663