最终效果:
先查全部
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