本文整理汇总了Java中com.reljicd.util.Pager类的典型用法代码示例。如果您正苦于以下问题:Java Pager类的具体用法?Java Pager怎么用?Java Pager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pager类属于com.reljicd.util包,在下文中一共展示了Pager类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: home
import com.reljicd.util.Pager; //导入依赖的package包/类
@GetMapping("/home")
public ModelAndView home(@RequestParam("pageSize") Optional<Integer> pageSize,
@RequestParam("page") Optional<Integer> page) {
// Evaluate page size. If requested parameter is null, return initial
// page size
int evalPageSize = pageSize.orElse(INITIAL_PAGE_SIZE);
// Evaluate page. If requested parameter is null or less than 0 (to
// prevent exception), return initial size. Otherwise, return value of
// param. decreased by 1.
int evalPage = (page.orElse(0) < 1) ? INITIAL_PAGE : page.get() - 1;
// Page<Post> posts = postService.findAllPageable(new PageRequest(evalPage, evalPageSize));
Page<Product> products = productService.findAllProductsPageable(new PageRequest(evalPage, evalPageSize));
Pager pager = new Pager(products.getTotalPages(), products.getNumber(), BUTTONS_TO_SHOW);
ModelAndView modelAndView = new ModelAndView();
// Collection<Post> posts = postService.findNLatestPosts(5);
modelAndView.addObject("products", products);
modelAndView.addObject("selectedPageSize", evalPageSize);
modelAndView.addObject("pageSizes", PAGE_SIZES);
modelAndView.addObject("pager", pager);
modelAndView.setViewName("home");
return modelAndView;
}
示例2: home
import com.reljicd.util.Pager; //导入依赖的package包/类
@GetMapping("/home")
public ModelAndView home(@RequestParam("pageSize") Optional<Integer> pageSize,
@RequestParam("page") Optional<Integer> page) {
// Evaluate page size. If requested parameter is null, return initial
// page size
int evalPageSize = pageSize.orElse(INITIAL_PAGE_SIZE);
// Evaluate page. If requested parameter is null or less than 0 (to
// prevent exception), return initial size. Otherwise, return value of
// param. decreased by 1.
int evalPage = (page.orElse(0) < 1) ? INITIAL_PAGE : page.get() - 1;
// Page<Post> posts = postService.findAllPageable(new PageRequest(evalPage, evalPageSize));
Page<Post> posts = postService.findAllOrderedByDatePageable(new PageRequest(evalPage, evalPageSize));
Pager pager = new Pager(posts.getTotalPages(), posts.getNumber(), BUTTONS_TO_SHOW);
ModelAndView modelAndView = new ModelAndView();
// Collection<Post> posts = postService.findNLatestPosts(5);
modelAndView.addObject("posts", posts);
modelAndView.addObject("selectedPageSize", evalPageSize);
modelAndView.addObject("pageSizes", PAGE_SIZES);
modelAndView.addObject("pager", pager);
modelAndView.setViewName("home");
return modelAndView;
}
示例3: blogForUsername
import com.reljicd.util.Pager; //导入依赖的package包/类
@RequestMapping(value = "/blog/{username}", method = RequestMethod.GET)
public ModelAndView blogForUsername(@PathVariable String username,
@RequestParam("pageSize") Optional<Integer> pageSize,
@RequestParam("page") Optional<Integer> page) {
// Evaluate page size. If requested parameter is null, return initial
// page size
int evalPageSize = pageSize.orElse(INITIAL_PAGE_SIZE);
// Evaluate page. If requested parameter is null or less than 0 (to
// prevent exception), return initial size. Otherwise, return value of
// param. decreased by 1.
int evalPage = (page.orElse(0) < 1) ? INITIAL_PAGE : page.get() - 1;
ModelAndView modelAndView = new ModelAndView();
User user = userService.findByUsername(username);
if (user == null) {
modelAndView.setViewName("404");
} else {
Page<Post> posts = postService.findByUserOrderedByDatePageable(user, new PageRequest(evalPage, evalPageSize));
Pager pager = new Pager(posts.getTotalPages(), posts.getNumber(), BUTTONS_TO_SHOW);
// modelAndView.addObject("posts", postService.findNLatestPostsForUser(10, user));
modelAndView.addObject("posts", posts);
modelAndView.addObject("selectedPageSize", evalPageSize);
modelAndView.addObject("pageSizes", PAGE_SIZES);
modelAndView.addObject("pager", pager);
modelAndView.addObject("user", user);
modelAndView.setViewName("posts");
}
return modelAndView;
}