private ListResult<Blog> getBlogsByPage(int pageNum, int pageSize) { // List<Blog> listOfBlogs = blogService.listAllBlog(); int currentPage, totalPage, totalCount; // 1. get total count // 2. totalPage = total count / 3 + ((total count % 3) == 0) ? 0 : 1 // 3. currentPage = page, currentPage -> items?? // 4. select blog_id from blog order by insertDate desc => list // 5. list ( [currentPage-1)*3 + 1, (currentPage)*3 ] ) => (set of blog_id) // 6. select * from blog where blog_id in (set of blog_id) |||| in (?) a = ? List<Integer> orderedIdList = blogService.listAllBlogIds(); for (int id : orderedIdList) { logger.debug("order id: " + id); } totalCount = orderedIdList.size(); logger.info("total count: " + totalCount); totalPage = totalCount / pageSize + (((totalCount % pageSize) == 0) ? 0 : 1); currentPage = pageNum; List<Integer> selectedIdList = new ArrayList<Integer>(); for (int k = ((currentPage - 1) * 3); k < (currentPage) * 3; ++k) { selectedIdList.add(orderedIdList.get(k)); logger.debug("added id: " + orderedIdList.get(k)); } List<Blog> listOfBlogs = blogService.getSelectedBlogs(selectedIdList); for (Blog b : listOfBlogs) { logger.debug("returned id: " + b.getBlogId()); } logger.info("totalPage:" + totalPage); logger.info("currentPage: " + currentPage); logger.info("list of blogs size: " + listOfBlogs.size()); ListResult<Blog> listResult = new ListResult<>(); listResult.setTotalPage(totalPage); listResult.setFetchedList(listOfBlogs); listResult.setCurrentPage(currentPage); return listResult; }