Bootstrap和Java分页实例第一篇(4)

package com.app.service.impl; import java.util.ArrayList; import java.util.List; import com.app.bean.Book; import com.app.pagination.Pagination; import com.app.pagination.impl.DefaultPagination; import com.app.service.BookService; /** * 使用List<T>集合模拟数据库 * @author: super.wwz@hotmail.com * @ClassName: BookServiceImpl2 * @Version: v0.1 */ public class BookServiceImpl2 implements BookService { // private BookDao bookDao = new BookDaoImpl(); private static List<Book> list = new ArrayList<Book>(); //初始化List<Book>数据 static { list.add(new Book(1, "书名1", 18)); list.add(new Book(2, "书名2", 13)); list.add(new Book(3, "书名3", 18)); list.add(new Book(4, "书名4", 38)); list.add(new Book(5, "书名5", 18)); list.add(new Book(6, "书名6", 58)); list.add(new Book(7, "书名7", 12)); list.add(new Book(8, "书名8", 11)); list.add(new Book(9, "书名9", 13)); list.add(new Book(10, "书名10", 22)); list.add(new Book(11, "书名11", 19)); list.add(new Book(12, "书名12", 13)); list.add(new Book(13, "书名13", 19)); list.add(new Book(14, "书名14", 32)); } @Override public Pagination<Book> getBookList(int pageIndex, int pageSize, int pageLinkNumber) { return new DefaultPagination<Book>(pageIndex, pageSize, new QueryHandler<Book>() { @Override public int getTotalElements() { //return bookDao.count(); return list.size(); } @Override public List<Book> getCurrData(int pageIndex, int pageSize) { //return bookDao.list(pageIndex, pageSize); int fromIndex = (pageIndex - 1) * pageSize; int endIndex = fromIndex + pageSize; endIndex = endIndex > list.size() ? list.size() : endIndex; return list.subList(fromIndex, endIndex); } }, pageLinkNumber); } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwjsgp.html