首頁 > web前端 > js教程 > 主體

JS元件Bootstrap Table使用實例分享

高洛峰
發布: 2017-01-04 11:08:02
原創
1632 人瀏覽過

學習使用bootstrap表格是對客戶端進行分頁的時候,在朋友的幫助下,找到了文檔http://bootstrap-table.wenzhixin.net.cn/examples/           Limit,和記錄開始數Offset。             
開始封裝,並分享我的程式碼,並從bootstrap table 取得頁碼和頁數,並交給後台處理。

$('#table').bootstrapTable({
  url: &#39;<%=path%>/FeedList.cqzk&#39;,
  striped: true,
  pagination: true,
  pageList: [3,5,20],
  pageSize:3,
  pageNumber:1,
  sidePagination:&#39;server&#39;,//设置为服务器端分页
  columns: [{
  field: &#39;title&#39;,
  title: &#39;标题&#39;
  }, {
  field: &#39;creatTime&#39;,
  title: &#39;时间&#39;
  } ]
 });
 
 
 
 @RequestMapping(value = "/FeedList.cqzk")
 @ResponseBody
 public String url_ad1(HttpServletRequest request,BootPage page) 
  throws ServletException,IOException,RuntimeException{
  
 @SuppressWarnings("unchecked") 
// List<Feedback> 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(); 
 // 不写.getString(0) 就多一个中括号,返回的就是数组,写了就是返回第一个对象。
 }
  
 
 
public BootPage getByPage(String hql,BootPage pager,Map<String, Object> condition){
 if (pager == null) {
  throw new IllegalArgumentException("分页 不能为空!");
 }
 
 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<String, Object> 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<T> {
  
 protected Long total;
  
 protected List<T> rows;
  
 protected int limit=0;
  
 protected int offset = 0;
  
 protected String order ="asc" ;
登入後複製

以上就是為大家分享的Bootstrap Table使用方法,希望對大家熟練Bootstrap Table使用方法有所幫助。

更多JS元件Bootstrap Table使用實例分享相關文章請關注PHP中文網!


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!