>  기사  >  웹 프론트엔드  >  JS 컴포넌트 Bootstrap Table 사용예 공유

JS 컴포넌트 Bootstrap Table 사용예 공유

高洛峰
高洛峰원래의
2017-01-04 11:08:021633검색

친구의 도움으로 클라이언트 페이지를 매길 때 부트스트랩 테이블을 사용하는 방법을 배웠습니다. http://bootstrap-table.wenzhixin.net.cn/examples/ 페이지당 레코드 수 제한 문서를 찾았습니다. 및 시작 레코드 수의 오프셋.
패키징을 시작하고, 내 코드를 공유하고, 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 중국어 웹사이트를 주목하세요!


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.