• https://www.cnblogs.com/guanghe/p/10026099.html

Server 类

@Slf4j
@Transactional
@Service
public class AvatarServiceImpl implements AvatarService {

	@Autowired
	private AvatarDao avatarDao ;
	
	@Autowired
	private PaginationProperties paginationProperties ; 
	
// do 。。。

	@Override
	public Page<Avatar> doFondPageObject(Integer pageCurrent, String name) {
		log.debug("doFondPageObject pageCurrent={} name={}",pageCurrent,name);
		Assert.isArgumentValid(pageCurrent==null||pageCurrent<1, "页码异常");
		/**查询:[分页前]总数据量*/
		Wrapper<Avatar> wrapper = //条件
				new EntityWrapper<Avatar>()
				.like(name!=null&&!"".equals(name),"name", name);
		Integer totalDataCount = //[分页前]总数据量
				avatarDao.selectCount(wrapper);
		Assert.isNoFound(totalDataCount==null||totalDataCount==0, "没有数据");
		/**查询分页*/
		Integer pageSize = 		//以后再定制化
				paginationProperties.getPageSize();
		int offset = 			//开始位置
				paginationProperties.getStartIndex(pageCurrent); 
		RowBounds rowBounds = 	//分页查询条件
				new RowBounds(offset, pageSize);
		List<Avatar> list = avatarDao.selectPage(rowBounds, wrapper); 
		Assert.isNoFound(list==null||list.size()==0, "没有数据!");
		return new Page<Avatar>(list, totalDataCount, pageCurrent, pageSize);
	}
}

其中 paginationProperties 、 page<T> 为自定义类

paginationProperties :

@Data
@Configuration
@ConfigurationProperties(prefix = "page.config")
public class PaginationProperties {

	/** * 默认 每页 数据量 */
	final static private Integer DEFAULT_PAGESIZE = 10 ;  
	
	/** * 每页多少条数据 */
	private Integer pageSize = DEFAULT_PAGESIZE ; 
	
	/** * 工具:计算分页的startIndex * @param pageCurrent 当前页码 1~n * @return startIndex */
	public Integer getStartIndex(Integer pageCurrent) {
		return (pageCurrent-1)*pageSize ; 
	}
	
}

page<T>

@Data
public class Page<T> implements Serializable{
	private static final long serialVersionUID = 7844855365725887051L;
	/**数据s*/
	private List<T> datas ;
	/**(分页前)总数据数*/
	private Integer totalDataCount = 0 ; 
	/**总页数*/
	private Integer pageTotal = 0 ; 
	/**当前页码*/
	private Integer pageCurrent = 1 ; 
	/**当前页数据量*/
	private Integer pageSize = 3;
	public Page(List<T> datas, Integer totalDataCount, Integer pageCurrent, Integer pageSize) {
		this.datas = datas;
		this.totalDataCount = totalDataCount;
		this.pageCurrent = pageCurrent;
		this.pageSize = pageSize;
		this.pageTotal = (totalDataCount-1)/pageSize + 1;
	}
	
}