当前位置:Gxlcms > JavaScript > JS组件Bootstrap Table使用实例分享

JS组件Bootstrap Table使用实例分享

时间:2021-07-01 10:21:17 帮助过:4人阅读

学习使用bootstrap表格是对客户端进行分页的时候,在朋友的帮助下,找到了文档http://bootstrap-table.wenzhixin.net.cn/examples/                 
找到了传到后台的每页条数Limit,和记录开始数Offset。             
开始封装,分享一下我的代码,从bootstrap table 获取页码和页数,并交给后台处理。

  1. $('#table').bootstrapTable({
  2. url: '<%=path%>/FeedList.cqzk',
  3. striped: true,
  4. pagination: true,
  5. pageList: [3,5,20],
  6. pageSize:3,
  7. pageNumber:1,
  8. sidePagination:'server',//设置为服务器端分页
  9. columns: [{
  10. field: 'title',
  11. title: '标题'
  12. }, {
  13. field: 'creatTime',
  14. title: '时间'
  15. } ]
  16. });
  17. @RequestMapping(value = "/FeedList.cqzk")
  18. @ResponseBody
  19. public String url_ad1(HttpServletRequest request,BootPage page)
  20. throws ServletException,IOException,RuntimeException{
  21. @SuppressWarnings("unchecked")
  22. // List<Feedback> list = feedBackDao.find("from Feedback");
  23. BootPage pager = feedBackDao.getByPage("from Feedback",page,null);
  24. System.out.println((JSONArray.fromObject(pager)).getString(0).toString());
  25. return (JSONArray.fromObject(pager)).getString(0).toString();
  26. // 不写.getString(0) 就多一个中括号,返回的就是数组,写了就是返回第一个对象。
  27. }
  28. public BootPage getByPage(String hql,BootPage pager,Map<String, Object> condition){
  29. if (pager == null) {
  30. throw new IllegalArgumentException("分页 不能为空!");
  31. }
  32. Query q = sessionFactory.getCurrentSession().createQuery(hql);
  33. q.setFirstResult(pager.getOffset());
  34. q.setMaxResults(pager.getLimit());
  35. if (condition != null) {
  36. q.setProperties(condition);
  37. }
  38. pager.setRows(q.list());
  39. pager.setTotal(this.countAll(hql, condition));
  40. return pager;
  41. }
  42. protected Long countAll(String hql, Map<String, Object> condition) {
  43. if (hql == null) {
  44. return 0l;
  45. }
  46. String tmpHql = hql.toLowerCase();
  47. String regex = hql.substring(0, tmpHql.indexOf("from"));
  48. hql = hql.replaceFirst(regex, "select count(*) ");
  49. Query q = sessionFactory.getCurrentSession().createQuery(hql);
  50. if (condition != null) {
  51. q.setProperties(condition);
  52. }
  53. return (Long) q.uniqueResult();
  54. }
  55. public final class BootPage<T> {
  56. protected Long total;
  57. protected List<T> rows;
  58. protected int limit=0;
  59. protected int offset = 0;
  60. protected String order ="asc" ;

如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:

Bootstrap学习教程

Bootstrap实战教程

Bootstrap插件使用教程

以上就是为大家分享的Bootstrap Table使用方法,希望对大家熟练掌握Bootstrap Table使用方法有所帮助。

人气教程排行