Example of using bootstrap-table to implement server paging (spring background ),

Source: Internet
Author: User

Example of using bootstrap-table to implement server paging (spring background ),

Recently, the bootstrap table plug-in is used on the front end. If the client page contains a large amount of data, it is difficult to interact with each other. Therefore, pages with large data volumes are used on the server side. The following starts the commit code:

Front end

First, let's take a look at the default paging parameter passed by bootstrap table.

  • Which subscript does offset start?
  • Limit per page

It may not be the same as our default paging parameter, so we decided to modify it. The parameter uploaded to the background is

  • Page number starting from 0
  • Size: The number displayed on each page.
$ ('#' + TableId ). bootstrapTable ({queryParams: function (e) {var param = {size: e. limit, page: (e. offset/e. limit), // + 1}; return param ;}, sidePagination: "server ";});


@ ApiOperation (value = "get Enterprise list, pagination supported", notes = "json method get User List") @ ApiImplicitParams ({@ ApiImplicitParam (name = "name ", value = "enterprise name", required = true, dataType = "string"), @ ApiImplicitParam (name = "beginTime", value = "Start time", required = true, dataType = "string")}) @ RequestMapping (value = "/list", method = RequestMethod. POST) @ ResponseBody public Map <String, Object> list (@ RequestParam Map <String, Object> m Ap, @ RequestParam (required = false) String name, @ RequestParam (required = false) String beginTime, @ RequestParam (required = false) String endTime, @ RequestParam (required = false) integer deptid) {List <Map <String, Object> list = new ArrayList <> (); // the current page number int page = map. get ("page") = null? 0: Integer. parseInt (map. get ("page"). toString (); // number of rows per page int size = map. get ("size") = null? 10: Integer. parseInt (map. get ("size "). toString (); Order order = new Order (Direction. ASC, "id"); Order order1 = new Order (Direction. DESC, "createTime"); List <Order> orders = new ArrayList <Order> (); orders. add (order1); // sort by createTime in descending order and then by id in ascending order orders. add (order); Sort sort = new Sort (orders); Pageable pageable = new PageRequest (page, size, sort); Page <Company> companyPages = null; if (StringKit. isEmpty (name) {companyPages = companyService. companyDao. findAll (pageable);} else {companyPages = companyService. companyDao. findByNameLike (name, pageable);} List <Company> companyList = companyPages. getContent (); SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"); for (Company company: companyList) {Map <String, object> mapTemp = BeanKit. describe (company); mapTemp. put ("createTime", sdf. format (company. getCreateTime (); list. add (mapTemp);} Map <String, Object> data = new HashMap <String, Object> (); data. put ("total", companyPages. getTotalElements (); data. put ("rows", list); return data ;}


The parameters received by bootstrap table must have total and rows, total is the total number, and rows is the number of each page.

Show it

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.