This article describes in detail how to use the JS component BootstrapTable pagination, which is practical. If you are interested, you can refer to learning to use the bootstrap table when paging the client, with the help of a friend, I found the document http://bootstrap-table.wenzhixin.net.cn/examples/
The number of lines on each page uploaded to the background is Limit, and the number of records starting Offset is found.
Start encapsulation, share my code, get the page number and page number from the bootstrap table, and hand it to the background for processing.
$ ('# Table '). bootstrapTable ({url: '<% = path %>/FeedList. cqzk ', striped: true, pagination: true, pageList: [3, 5, 20], pageSize: 3, pageNumber: 1, sidePagination: 'server ', // set it to server-side paging columns: [{field: 'title', title: 'title'}, {field: 'creattime', title: 'time'}]}); @ RequestMapping (value = "/FeedList. cqzk ") @ ResponseBody public String url_ad1 (HttpServletRequest request, BootPage page) throws ServletException, IOException, RuntimeException {@ SuppressWarnings (" unchecked ") // List
List = feedBackDao. find ("from Feedback"); BootPage pager = feedBackDao. getByPage ("from Feedback", page, null); System. out. println (JSONArray. fromObject (pager )). getString (0 ). toString (); return (JSONArray. fromObject (pager )). getString (0 ). toString (); // do not write. getString (0) has one more square brackets, and returns an array. If it is written, it returns the first object. } Public BootPage getByPage (String hql, BootPage pager, Map
Condition) {if (pager = null) {throw new IllegalArgumentException ("the page cannot be blank! ");} Query q = sessionFactory. getCurrentSession (). createQuery (hql); q. setFirstResult (pager. getOffset (); q. setMaxResults (pager. getLimit (); if (condition! = Null) {q. setProperties (condition);} pager. setRows (q. list (); pager. setTotal (this. countAll (hql, condition); return pager;} protected Long countAll (String hql, Map
Condition) {if (hql = null) {return 0l;} String tmpHql = hql. toLowerCase (); String regex = hql. substring (0, tmpHql. indexOf ("from"); hql = hql. replaceFirst (regex, "select count (*)"); Query q = sessionFactory. getCurrentSession (). createQuery (hql); if (condition! = Null) {q. setProperties (condition);} return (Long) q. uniqueResult ();} public final class BootPage
{Protected Long total; protected List
Rows; protected int limit = 0; protected int offset = 0; protected String order = "asc ";
The above is the Bootstrap Table usage method shared for you. It is helpful for you to master the Bootstrap Table usage method.
For more articles about how to use the JS component Bootstrap Table to share instances, refer to PHP!