品优购学习笔记二-品牌列表分页的实现

1.品牌列表分页的实现

效果展示:


7149586-99f2b1523aaef466.png
1557319280449.png

1.1后端代码

1.1.1 分页结果封装实体

package entity;

import java.io.Serializable;
import java.util.List;

public class PageResult implements Serializable{
    
    private static final long serialVersionUID = 1L;
    private long total;
    private List rows;
    
    public PageResult(long total, List rows) {
        super();
        this.total = total;
        this.rows = rows;
    }
    public long getTotal() {
        return total;
    }
    public void setTotal(long total) {
        this.total = total;
    }
    public List getRows() {
        return rows;
    }
    public void setRows(List rows) {
        this.rows = rows;
    }
    
}

1.1.2服务接口层

    /**
     * 返回分页列表
     * @return
     */
    public PageResult findPage(int pageNum,int pageSize);

1.1.3服务实现层

@Override
public PageResult findPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);        
        Page<TbBrand> page=   (Page<TbBrand>) brandMapper.selectByExample(null);
        return new PageResult(page.getTotal(), page.getResult());
    }

PageHelper为MyBatis分页插件

7149586-467e0cbc276e17a5.png
1557319764350.png

1.1.4 控制层

    /**
     *返回全部列表
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/findPage")
    public PageResult  findPage(int page,int rows){         
        return brandService.findPage(page, rows);
    }
    

运行结果:

7149586-7a8d24460f860d08.png
1557320219867.png

1.2前端代码

在brand.html引入分页组件

<!-- 分页组件开始 -->
<script src="../plugins/angularjs/pagination.js"></script>
<link rel="stylesheet" href="../plugins/angularjs/pagination.css">
<!-- 分页组件结束 -->

构建app模块时引入pagination模块


7149586-1a82be2265711a2c.png
1557320443187.png

在brandController中添加如下代码

//重新加载列表 数据
$scope.reloadList=function(){
     //切换页码  
$scope.findPage( $scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
}
//分页控件配置 
$scope.paginationConf = {
         currentPage: 1,
         totalItems: 10,
         itemsPerPage: 10,
         perPageOptions: [10, 20, 30, 40, 50],
         onChange: function(){
                     $scope.reloadList();//重新加载
         }
}; 
//分页
$scope.findPage=function(page,rows){    
    $http.get('../brand/findPage.do?page='+page+'&rows='+rows).success(
            function(response){
                $scope.list=response.rows;  
                $scope.paginationConf.totalItems=response.total;//更新总记录数
            }           
    );
}

  • currentPage:当前页码
  • totalItems:总条数
  • itemsPerPage:
  • perPageOptions:页码选项
  • onChange:更改页面时触发事件

github地址:https://github.com/smallmartial/pinyougou>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值