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 ";});
Background
@ 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 ;}
Notes
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.