分页

提供一个例子

结构

  1. type Page struct {
  2. PageNo int
  3. PageSize int
  4. TotalPage int
  5. TotalCount int
  6. FirstPage bool
  7. LastPage bool
  8. List interface{}
  9. }
  10. func PageUtil(count int, pageNo int, pageSize int, list interface{}) Page {
  11. tp := count / pageSize
  12. if count % pageSize > 0 {
  13. tp = count / pageSize + 1
  14. }
  15. return Page{PageNo: pageNo, PageSize: pageSize, TotalPage: tp, TotalCount: count, FirstPage: pageNo == 1, LastPage: pageNo == tp, List: list}
  16. }

页面是使用 js 插件进行分页 https://github.com/lyonlai/bootstrap-paginator

  1. <script type="text/javascript" src="/static/js/bootstrap-paginator.min.js"></script>
  2. <script type="text/javascript">
  3. $(function () {
  4. $("#page").bootstrapPaginator({
  5. currentPage: '{{.Page.PageNo}}',
  6. totalPages: '{{.Page.TotalPage}}',
  7. bootstrapMajorVersion: 3,
  8. size: "small",
  9. onPageClicked: function(e,originalEvent,type,page){
  10. window.location.href = "/?p=" + page
  11. }
  12. });
  13. });
  14. </script>