最终效果:

先查全部
1.后端
我们需要建立一个实体类,PageResult.java(加上get,set方法和构造方法,实现序列化)
定义 总页数和行数
package entity;
import java.io.Serializable;
import java.util.List;
/**
* 分页总结果,总页数和行数
* @author zly
*
*/
public class PageResult implements Serializable {
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;
}
}
通过controller,service,serviceimpl查询到所有数据后,最后通过alibaba的fastjson返回的是json数据,格式如下:
[{
"firstChar": "L",
"id": 1,
"name": "联想"
}, {
"firstChar": "Y",
"id": 25,
"name": "优衣库"
}]
2.前台显示
前台展示需要写angularjs指令,主要是在body标签里写,然后和script里的而对应
ng-app=“pinyougou”----可以写成项目名称
ng-controller=“brandController”----可以写成模块名称
ng-init=“findAll()”----作用是随页面加载
ng-repeat=“entity in list”----遍历,相当于jstl表达式中的<for:each>
ng-click=“findPage()”----事件,相当于js里的onclick
js部分:
<script type="text/javascript" src="../plugins/angularjs/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('pinyougou', [ '' ]);
app

本文介绍了如何在AngularJS应用中实现分页功能。首先展示了最终的分页效果,接着详细讲解了后端如何处理分页,包括创建PageResult实体类,利用Alibaba的FastJSON返回JSON数据。在前端,通过编写AngularJS指令在body中展示数据,并实现了ng-repeat遍历及ng-click事件处理。在后处理分页部分,阐述了后端如何通过接收pageNum和pageSize参数进行分页查询,以及前端如何引入并使用分页插件来显示分页信息。
最低0.47元/天 解锁文章
168

被折叠的 条评论
为什么被折叠?



