bootstrap-table實現伺服器分頁的樣本 (spring 後台),

來源:互聯網
上載者:User

bootstrap-table實現伺服器分頁的樣本 (spring 後台),

最近前端都是用的bootstrap table這個外掛程式,用戶端分頁的話資料量一多互動不好,所以大資料量的分頁都用伺服器端,下面開始擼代碼

前端

首先看下bootstrap table 預設傳的分頁參數是什麼

  • offset 從哪個下標開始
  • limit 每頁限制的數量

可能跟我們的預設分頁參數不大一樣吧,所以決定改造一下,傳到背景參數為

  • page 第幾頁 從0開始
  • size 每頁顯示的數量
  $('#' + tableId).bootstrapTable({     queryParams: function (e) {       var param = {        size: e.limit,        page: (e.offset / e.limit),//不需要+1              };       return param;      },     sidePagination:“server”;});

後台 

 @ApiOperation(value = "擷取企業列表,支援分頁", notes = "json方法擷取使用者列表") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "企業名稱", required = true, dataType = "string"), @ApiImplicitParam(name = "beginTime", value = "開始時間", 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<>();  //當前頁數  int page = map.get("page")== null ? 0 : Integer.parseInt(map.get("page").toString());  // 每頁行數  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; }

注意點

bootstrap table接收的參數中必須要有total和rows,total就是總數量,rows是每頁的數量

展示一下吧

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.