bootstrap-table實(shí)現(xiàn)服務(wù)器分頁的示例 (spring 后臺(tái))
最近前端都是用的bootstrap table這個(gè)插件,客戶端分頁的話數(shù)據(jù)量一多交互不好,所以大數(shù)據(jù)量的分頁都用服務(wù)器端,下面開始擼代碼
前端
首先看下bootstrap table 默認(rèn)傳的分頁參數(shù)是什么
- offset 從哪個(gè)下標(biāo)開始
- limit 每頁限制的數(shù)量
可能跟我們的默認(rèn)分頁參數(shù)不大一樣吧,所以決定改造一下,傳到后臺(tái)的參數(shù)為
- page 第幾頁 從0開始
- size 每頁顯示的數(shù)量
$('#' + tableId).bootstrapTable({ queryParams: function (e) { var param = { size: e.limit, page: (e.offset / e.limit),//不需要+1 }; return param; }, sidePagination:“server”; });
后臺(tái)
@ApiOperation(value = "獲取企業(yè)列表,支持分頁", notes = "json方法獲取用戶列表") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "企業(yè)名稱", required = true, dataType = "string"), @ApiImplicitParam(name = "beginTime", value = "開始時(shí)間", required = true, dataType = "string") }) @RequestMapping(value="/list",method=RequestMethod.POST) @ResponseBody public Map<String,Object> list(@RequestParam Map<String,Object> map,@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<>(); //當(dāng)前頁數(shù) int page = map.get("page")== null ? 0 : Integer.parseInt(map.get("page").toString()); // 每頁行數(shù) 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);//先按照createTime 降序排序 然后按照id升序 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; }
注意點(diǎn)
bootstrap table接收的參數(shù)中必須要有total和rows,total就是總數(shù)量,rows是每頁的數(shù)量
展示一下效果圖吧
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- bootstrap table表格插件之服務(wù)器端分頁實(shí)例代碼
- bootstrap table 服務(wù)器端分頁例子分享
- bootstrap-table后端分頁功能完整實(shí)例
- Bootstrap table分頁問題匯總
- 第一次動(dòng)手實(shí)現(xiàn)bootstrap table分頁效果
- bootstrap table插件的分頁與checkbox使用詳解
- BootStrap中Table分頁插件使用詳解
- BootStrap Table前臺(tái)和后臺(tái)分頁對(duì)JSON格式的要求
- bootstrap table分頁模板和獲取表中的ID方法
- 使用bootstraptable插件實(shí)現(xiàn)表格記錄的查詢、分頁、排序操作
- BootStrap Table后臺(tái)分頁時(shí)前臺(tái)刪除最后一頁所有數(shù)據(jù)refresh刷新后無數(shù)據(jù)問題
- Bootstrap table 服務(wù)器端分頁功能實(shí)現(xiàn)方法示例
相關(guān)文章
JS實(shí)現(xiàn)重新加載當(dāng)前頁面或者父頁面的幾種方法
本文介紹了JS實(shí)現(xiàn)重新加載當(dāng)前頁面或者父頁面的幾種方法.需要的朋友可以參考下2016-11-11使用js實(shí)現(xiàn)關(guān)閉js彈出層的窗口
本篇文章主要是對(duì)使用js實(shí)現(xiàn)關(guān)閉js彈出層的窗口的示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-02-02JS基于面向?qū)ο髮?shí)現(xiàn)的多個(gè)倒計(jì)時(shí)器功能示例
這篇文章主要介紹了JS基于面向?qū)ο髮?shí)現(xiàn)的多個(gè)倒計(jì)時(shí)器功能,結(jié)合實(shí)例形式分析了javascript面向?qū)ο蠹皶r(shí)間操作相關(guān)技巧,需要的朋友可以參考下2017-02-02關(guān)于Javascript 的 prototype問題。
關(guān)于Javascript 的 prototype問題。...2007-01-01