Home >Web Front-end >JS Tutorial >Sharing of usage examples of JS component Bootstrap Table

Sharing of usage examples of JS component Bootstrap Table

高洛峰
高洛峰Original
2017-01-04 11:08:021712browse

When I learned to use the bootstrap table to paginate the client, with the help of my friends, I found the document http://bootstrap-table.wenzhixin.net.cn/examples/                                                                                             Limit of the number of records per page, and Offset of the starting number of records.​​​​​​
Start packaging, share my code, get the page number and number of pages from the bootstrap table, and hand it over to the background for processing.

$('#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" ;

The above is how to use Bootstrap Table shared with you. I hope it will be helpful for everyone to master the use of Bootstrap Table.

For more JS component Bootstrap Table usage examples and related articles, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn