user5324782 user5324782 - 2 years ago 135
JSON Question

Sping MVC pagination

the database user table is huge, it would take 15 mins to finish a select statement
so I am using this query:

select * from (
select * from user order by userId desc
) where ROWNUM > offset and ROWNUM <= offset + itemsPerPage;

then my DOA service method looks like

public List<User> getUserRange(int offset 1, limit itemsPerPage){

mybatis code

The user object

public class User{
String userName;
String userDOB;
String userAddress;
.....setters and getters

and I want to display it in a simple JSP page, my problem is most examples on the internet would need to retrieve the User List in a single select statement

but I want the JSP page to display all the page numbers and when user clicks each page number, the number gets passed into the getUserRange() method, a fresh list of users can be rendered.

I did look into some taglibs on the github, haven't got much luck, if anyone could point me to the right direction, would be much appreciated.

Answer Source

there are a few options:

I am not including any samples here, because you can find on each one of those libraries official webwite

the old fashioned way using the displayTag


which is a JSP oriented implementation doesn't utilizing new technologies such as Json, Jquery-UI, the development seems not so active

the popular way using the jquery-plugin datatables some say this is one of the most popular pagination plugin for the Java stack, currently very active, in my opinion offers most comprehensive features



the way I did it using another jquery-plugin jTable



Comparisons: both jTable and datatables are based on json and jquery, at the time of the post it's very trendy thing to do, and better design compare to the old fashioned display tag

I found jTable is easier to understand, but datatables is more popular among my fellow developers. and I am certainly not recommend using any of the old fashioned displayTag technology

Webjars if anyone of you wondering what webjars is, please take a look of this in short it stops you manually download and dropping jquery.js or other JavaScript libs in your /webapp/WEB-INF/*** folder. by using Maven to manage all your web dependencies.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download