Angularjs分页

Angularjs分页
先创建一个结果类:
public class PageResult implements Serializable {
private long total;

private List<T> rows;

public PageResult(long total, List<T> rows) {
    this.total = total;
    this.rows = rows;
}

public long getTotal() {
    return total;
}

public void setTotal(long total) {
    this.total = total;
}

public List<T> getRows() {
    return rows;
}

public void setRows(List<T> rows) {
    this.rows = rows;
}

}
js代码片段:
app.controller(‘baseController’,function ( s c o p e , scope, http) {
// 分页控件配置
// currentPage:当前页;totalItems:总记录数;itemsPerPage:每页记录数;perPageOptions:分页选项;onChange:当页码变更后自动触发的方法
$scope.paginationConf = {
currentPage: 1,
totalItems: 10,
itemsPerPage: 10,
perPageOptions: [10, 20, 30, 40, 50],
onChange: function () {
$scope.reloadList();//重新加载
}
};

//重新加载列表 数据
$scope.reloadList = function () {
//切换页码
s c o p e . f i n d P a g e ( scope.findPage( scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
};
$scope.findPage=function(page,size){
brandService.findPage(page,size).success(
function(response){
$scope.list=response.rows;
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
};
Controller:片段
@RequestMapping("/findPage/{page}/{size}")
public PageResult findPage(@PathVariable(“page”) int page, @PathVariable(“size”) int size) {
return brandService.findPage(page, size);
}
Service实现类片段:
@Override
public PageResult findPage(int page, int size) {
//1.调用pagehelper的startPage方法
PageHelper.startPage(page, size);
//2.调用正常查询,将结果强转成Page
Page pageReturn = (Page)tbSpecificationMapper.selectByExample(null);
//3.将page中的值(总条数和每页显示的数据集合)封装到PageResult,返回
return new PageResult<>(pageReturn.getTotal(), pageReturn.getResult());
}

猜你喜欢

转载自blog.csdn.net/weixin_42957419/article/details/84581701