代码是用Maven管理的
Controller代码
package cn.masterYi.controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.masterYi.util.JsonResult;
public abstract class BaseController {
@ExceptionHandler(Exception.class)
@ResponseBody
public JsonResult exceptionHandle(Exception e) {
//参数e就是被捕获到的异常对�?
e.printStackTrace();
System.out.println("exceptionHandle");
return new JsonResult(e);
}
}
package cn.masterYi.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import cn.masterYi.entity.pageList;
import cn.masterYi.service.pagesList;
import cn.masterYi.util.JsonResult;
@Controller
@RequestMapping("/page")
public class pagingController extends BaseController {
@Resource
private pagesList pageslist;
@ResponseBody
@RequestMapping(value = "/actions.do")
public Object paging(int pagenum) {
List<pageList> list = pageslist.listpage(pagenum);
int nums = pageslist.pagenum();
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("list", (Object) list);
map.put("num", nums);
return new JsonResult(map);
}
}
Java实体类代码
package cn.masterYi.entity;
public class pageList {
private String spdh;
private String yspdh;
private String cglx;
private String spzt;
private String dqspr;
private String date;
public pageList(String spdh, String yspdh, String cglx, String spzt, String dqspr, String date) {
this.spdh = spdh;
this.yspdh = yspdh;
this.cglx = cglx;
this.spzt = spzt;
this.dqspr = dqspr;
this.date = date;
}
public pageList() {
}
public String getSpdh() {
return spdh;
}
public void setSpdh(String spdh) {
this.spdh = spdh;
}
public String getYspdh() {
return yspdh;
}
public void setYspdh(String yspdh) {
this.yspdh = yspdh;
}
public String getCglx() {
return cglx;
}
public void setCglx(String cglx) {
this.cglx = cglx;
}
public String getSpzt() {
return spzt;
}
public void setSpzt(String spzt) {
this.spzt = spzt;
}
public String getDqspr() {
return dqspr;
}
public void setDqspr(String dqspr) {
this.dqspr = dqspr;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
@Override
public String toString() {
return "pageList [spdh=" + spdh + ", yspdh=" + yspdh + ", cglx=" + cglx + ", spzt=" + spzt + ", dqspr=" + dqspr
+ ", date=" + date + "]";
}
}
package cn.masterYi.util;
import java.io.Serializable;
public class JsonResult implements Serializable{
private static final long serialVersionUID = 812376774103405857L;
private int state;
private Object data;
private String message;
public static final int SUCCESS=0;
public static final int ERROR=1;
public JsonResult(){}
public JsonResult(int state,Throwable e){
this.state=state;
data=null;
message=e.getMessage();
}
public JsonResult(int state, Object data, String message) {
this.state = state;
this.data = data;
this.message = message;
}
public JsonResult(Throwable e){
state=ERROR;
data=null;
message=e.getMessage();
}
public JsonResult(Object data){
state=SUCCESS;
this.data=data;
message="";
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return "JsonResult [state=" + state + ", data=" + data + ", message=" + message + "]";
}
}
接口类
package cn.masterYi.service;
import java.util.List;
import cn.masterYi.entity.pageList;
public interface pagesList {
List<pageList> listpage(int pagenum);
int pagenum();
}
业务实现类
package cn.masterYi.service;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import cn.masterYi.entity.pageList;
@Service("pageList")
public class pagesListImpl implements pagesList {
List<pageList> pageing;
public List<pageList> listpage(int pagenum) {
pageing = new ArrayList<pageList>();
List<pageList> pageings = new ArrayList<pageList>();
System.out.println("123eerr");
for (int i = 1; i <60; i++) {
pageing.add(new pageList("A000"+i,"A0000"+i,"采购付款","待审批","高**","2017-07-20"));
}
if((pageing.size()-pagenum*3)>0){
for(int i=(pagenum-1)*3;i<pagenum*3;i++){
pageings.add(pageing.get(i));
}
return pageings;
}else{
for(int i=(pagenum-1)*3;i<pageing.size();i++){
pageings.add(pageing.get(i));
}
}
return pageings;
}
public int pagenum() {
return pageing.size();
}
}
前端代码
js代码
window.onload = function (){
var pagenum=1;
$.ajax({
url:'notebook/actions.do?pagenum=1',
type:'get',
dataType: 'json',
success: function(ary){
var datas = ary.data;
for(var k=1;k<=(datas.num+1)/3;k++){ //通过循环增加按钮
$('#map-result').append(
'<button class="btn btn-success" id="page_'+k+'">'+k+'</button>'//
)
}
for(var i=0; i<datas.list.length; i++){ //第一次进入需要加载3条数据
var obj = datas.list[i];
$('#map2').append(
'<div id=style="margin-bottom:40px;margin-top: 80px; ">'+'<p>'+'审批单号: <span><a href="http://www.baidu.com">'+obj.spdh+'</a></span></p>'+'<br>'+'<p>'+'原始单据号: '+obj.yspdh+'<br><br>'+'单据类型: '+
obj.cglx+'</p>'+'<br>'+'<p>'+'审批状态: '+obj.spzt+' 当前审批人: '+obj.dqspr+'</p>'+'<br>'+'<p>'+
'提交时间: '+obj.date+'</p>'+'</div>'+'<hr>');
}
}
})
document.body.onclick = function(event){ //利用事件冒泡处理找出被点击按钮的id
var id = event.target.id;
var strs = id.split("_");
if(strs[0]=="page"){
pagenum=strs[1];
$.ajax({
url:'notebook/actions.do?pagenum='+pagenum,
type:'get',
dataType: 'json',
success: function(ary){
var datas = ary.data;
document.getElementById('map2').innerHTML = ""; //清空当前页面的内容
for(var j=0; j<datas.list.length; j++){ //为当前页面添加新的内容
var obj = datas.list[j];
$('#map2').append(
'<div id=style="margin-bottom:40px;margin-top: 80px; ">'+'<p>'+'审批单号: <span><a href="http://www.baidu.com">'+obj.spdh+'</a></span></p>'+'<br>'+'<p>'+'原始单据号: '+obj.yspdh+'<br><br>'+'单据类型: '+
obj.cglx+'</p>'+'<br>'+'<p>'+'审批状态: '+obj.spzt+' 当前审批人: '+obj.dqspr+'</p>'+'<br>'+'<p>'+
'提交时间: '+obj.date+'</p>'+'</div>'+'<hr>');
}
}
})
}
}
}
css代码
a{
color: #000;
}
#map2-result{
margin-top: 60px;
margin-left: 40px;
margin-bottom:40px;
line-height:15px;
font-family:"等线";
margin-bottom:
style="text-decoration:none; color:#000;"
}
html代码
<body>
<div id="map2" style=" font-size: 19px;">
</div>
<div id="map-result" class="" style="text-align:center;">
</div>
</body>
github项目地址:https://github.com/YiPan007/Netty/tree/master/paging