标题一、关于分页常用的代码
pageUtils
@Data @AllArgsConstructor @NoArgsConstructor public class PageUtils<T> { private Integer pageIndex;//当前页码 private Integer pageSize;//每页条数 private Integer totalCount;//总条数 private Integer pageCount;//总页数 private List<T> records;//每页数据 //存储页面需要显示的页码 private List<Integer> numbers=new ArrayList<>(); //开始序号 private Integer numberStart=1; //结束的序号 private Integer numberEnd; public PageUtils(Integer pageIndex, Integer pageSize, Integer totalCount, List<T> records) { this.pageIndex = pageIndex; this.pageSize = pageSize; this.totalCount = totalCount; this.records = records; this.pageCount=(this.totalCount%pageSize==0)?(totalCount/pageSize):(totalCount/pageSize+1); this.numberStart=1; this.numberEnd=pageCount; //限制页码个数问题 if (this.pageCount<=10){ //总页数小于10页 this.numberStart=1; this.numberEnd=this.pageCount; }else { this.numberStart=this.pageIndex-4; this.numberEnd=this.pageIndex+5; //判断前后越界 if (this.numberStart<1){ //前面越界 this.numberStart=1; this.numberEnd=10; }else if (this.numberEnd>this.pageCount){ //判断后面越界 this.numberEnd=this.getPageCount(); this.numberStart=this.pageCount-9; } } for(int i=this.numberStart;i<=this.numberEnd;i++){ numbers.add(i); } } }
标题二、通用的跳转页面
/* * 通用的跳转页面 * */ //在controller层中 @RequestMapping("/page_{page}") public String page(@PathVariable("page") String page){ return page; }
标题三、和前端页面交互信息
MessageResults
@Data @NoArgsConstructor @AllArgsConstructor public class MessageResults { private Integer code; private String message; }