写一下分页吧

1,在js先开启分页

,page:true
2,在controller创建分页的参数limit和page,allDorm只是全查询的方法而已不要在意

@RequestMapping("/allDorm")
@ResponseBody
public String allDorm(int limit, int page){
JsonData jsonData = dormService.allDorm(limit,page);
return JSON.toJSONString(jsonData);
}
3,在service创建分页的方法
@Override
public JsonData allDorm(int limit, int page) {
// 开启分页
PageHelper.startPage(page, limit);
List<Dorm> depts = dormMapper.allDorm();
// 将查询到的数据封装到分页的对象中
PageInfo<Dorm> pageInfo = new PageInfo<>(depts);
return JsonData.buildSuccess(pageInfo, "success");
}
4,在JS的table后写
,parseData:function(rs){//数据格式解析
console.log("rs===="+rs.toString()+"---"+rs.data.total+"---"+rs.data.list+"---"+rs.msg)
return { // 里面的每一个值必须与传递的json 数据对应
"code":rs.code, //返回状态码200
"msg":rs.msg, // 消息
"count":rs.data.total, //总条目
"data":rs.data.list //具体内容
}
}
 
原文地址:https://www.cnblogs.com/lixuze/p/14238985.html