Java Code Examples for cn.hutool.core.util.PageUtil#rainbow()

The following examples show how to use cn.hutool.core.util.PageUtil#rainbow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrontIndexController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 首页分页
 *
 * @param model model
 * @param page  当前页码
 * @param size  每页数量
 * @return 模板路径/themes/{theme}/index
 */
@GetMapping(value = "page/{page}")
public String index(Model model,
                    @PathVariable(value = "page") Integer page) {
    final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    //默认显示10条
    int size = 10;
    if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
    }
    //所有文章数据,分页
    final Pageable pageable = PageRequest.of(page - 1, size, sort);
    final Page<Post> posts = postService.findPostByStatus(pageable);
    if (null == posts) {
        return this.renderNotFound();
    }
    final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
    model.addAttribute("is_index",true);
    model.addAttribute("posts", posts);
    model.addAttribute("rainbow", rainbow);
    return this.render("index");
}
 
Example 2
Source File: FrontTagController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据标签路径查询所有文章 分页
 *
 * @param model  model
 * @param tagUrl 标签路径
 * @param page   页码
 *
 * @return String
 */
@GetMapping(value = "{tagUrl}/page/{page}")
public String tags(Model model,
                   @PathVariable("tagUrl") String tagUrl,
                   @PathVariable("page") Integer page) {
    final Tag tag = tagService.findByTagUrl(tagUrl);
    if (null == tag) {
        return this.renderNotFound();
    }
    final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    int size = 10;
    if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
    }
    final Pageable pageable = PageRequest.of(page - 1, size, sort);
    final Page<Post> posts = postService.findPostsByTags(tag, pageable);
    final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
    model.addAttribute("is_tags", true);
    model.addAttribute("posts", posts);
    model.addAttribute("rainbow", rainbow);
    model.addAttribute("tag", tag);
    return this.render("tag");
}
 
Example 3
Source File: FrontCategoryController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据分类目录查询所有文章 分页
 *
 * @param model   model
 * @param cateUrl 分类目录路径
 * @param page    页码
 *
 * @return String
 */
@GetMapping("{cateUrl}/page/{page}")
public String categories(Model model,
                         @PathVariable("cateUrl") String cateUrl,
                         @PathVariable("page") Integer page) {
    final Category category = categoryService.findByCateUrl(cateUrl);
    if (null == category) {
        return this.renderNotFound();
    }
    final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    int size = 10;
    if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
    }
    final Pageable pageable = PageRequest.of(page - 1, size, sort);
    final Page<Post> posts = postService.findPostByCategories(category, pageable);
    final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
    model.addAttribute("is_categories", true);
    model.addAttribute("posts", posts);
    model.addAttribute("rainbow", rainbow);
    model.addAttribute("category", category);
    return this.render("category");
}
 
Example 4
Source File: FrontIndexController.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 首页分页
 *
 * @param model model
 * @param page  当前页码
 * @param size  每页数量
 * @return 模板路径/themes/{theme}/index
 */
@GetMapping(value = "page/{page}")
public String index(Model model,
                    @PathVariable(value = "page") Integer page) {
    Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    //默认显示10条
    int size = 10;
    //尝试加载设置选项,用于设置显示条数
    if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
    }
    //所有文章数据,分页
    Pageable pageable = PageRequest.of(page - 1, size, sort);
    Page<Post> posts = postService.findPostByStatus(pageable);
    if (null == posts) {
        return this.renderNotFound();
    }
    int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
    model.addAttribute("is_index",true);
    model.addAttribute("posts", posts);
    model.addAttribute("rainbow", rainbow);
    return this.render("index");
}
 
Example 5
Source File: FrontTagController.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 根据标签路径查询所有文章 分页
 *
 * @param model  model
 * @param tagUrl 标签路径
 * @param page   页码
 * @return String
 */
@GetMapping(value = "{tagUrl}/page/{page}")
public String tags(Model model,
                   @PathVariable("tagUrl") String tagUrl,
                   @PathVariable("page") Integer page) {
    Tag tag = tagService.findByTagUrl(tagUrl);
    if(null==tag){
        return this.renderNotFound();
    }
    Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    Integer size = 10;
    if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
    }
    Pageable pageable = PageRequest.of(page - 1, size, sort);
    Page<Post> posts = postService.findPostsByTags(tag, pageable);
    int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
    model.addAttribute("is_tags",true);
    model.addAttribute("posts", posts);
    model.addAttribute("rainbow", rainbow);
    model.addAttribute("tag", tag);
    return this.render("tag");
}
 
Example 6
Source File: FrontCategoryController.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 根据分类目录查询所有文章 分页
 *
 * @param model   model
 * @param cateUrl 分类目录路径
 * @param page    页码
 * @return String
 */
@GetMapping("{cateUrl}/page/{page}")
public String categories(Model model,
                         @PathVariable("cateUrl") String cateUrl,
                         @PathVariable("page") Integer page) {
    Category category = categoryService.findByCateUrl(cateUrl);
    if (null == category) {
        return this.renderNotFound();
    }
    Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    Integer size = 10;
    if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
    }
    Pageable pageable = PageRequest.of(page - 1, size, sort);
    Page<Post> posts = postService.findPostByCategories(category, pageable);
    int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
    model.addAttribute("is_categories",true);
    model.addAttribute("posts", posts);
    model.addAttribute("rainbow", rainbow);
    model.addAttribute("category", category);
    return this.render("category");
}
 
Example 7
Source File: CommentServiceImpl.java    From SENS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CommentPageDTO findCommentPageByPostId(Long postId, Integer pageNumber) {
    List<Comment> comments = this.findCommentsByPostAndCommentStatus(postId, CommentStatusEnum.PUBLISHED.getCode());
    //默认显示10条
    Integer size = 10;
    //获取每页评论条数
    if (!StringUtils.isBlank(SensConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) {
        size = Integer.parseInt(SensConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()));
    }
    //评论分页
    ListPage<Comment> commentsPage = new ListPage<Comment>(CommentUtil.getComments(comments), pageNumber, size);
    int[] rainbow = PageUtil.rainbow(pageNumber, commentsPage.getTotalPage(), 10);
    return new CommentPageDTO(commentsPage, rainbow);
}
 
Example 8
Source File: FrontPageController.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 渲染自定义页面
 *
 * @param postUrl 页面路径
 * @param model   model
 *
 * @return 模板路径/themes/{theme}/post
 */
@GetMapping(value = "/p/{postUrl}")
public String getPage(@PathVariable(value = "postUrl") String postUrl,
                      @RequestParam(value = "cp", defaultValue = "1") Integer cp,
                      Model model) {
    final Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc());
    if (null == post || !post.getPostStatus().equals(PostStatusEnum.PUBLISHED.getCode())) {
        return this.renderNotFound();
    }
    List<Comment> comments = null;
    if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) {
        comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatusEnum.PUBLISHED.getCode());
    } else {
        comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatusEnum.RECYCLE.getCode());
    }
    //默认显示10条
    int size = 10;
    if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()));
    }
    //评论分页
    final ListPage<Comment> commentsPage = new ListPage<Comment>(CommentUtil.getComments(comments), cp, size);
    final int[] rainbow = PageUtil.rainbow(cp, commentsPage.getTotalPage(), 3);
    model.addAttribute("is_page", true);
    model.addAttribute("post", post);
    model.addAttribute("comments", commentsPage);
    model.addAttribute("commentsCount", comments.size());
    model.addAttribute("rainbow", rainbow);
    postService.cacheViews(post.getPostId());

    //如果设置了自定义模板,则渲染自定义模板
    if (StrUtil.isNotEmpty(post.getCustomTpl())) {
        return this.render(post.getCustomTpl());
    }
    return this.render("page");
}
 
Example 9
Source File: FrontPageController.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
/**
 * 渲染自定义页面
 *
 * @param postUrl 页面路径
 * @param model   model
 * @return 模板路径/themes/{theme}/post
 */
@GetMapping(value = "/p/{postUrl}")
public String getPage(@PathVariable(value = "postUrl") String postUrl,
                      @RequestParam(value = "cp", defaultValue = "1") Integer cp,
                      Model model) {
    Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc());
    if (null == post) {
        return this.renderNotFound();
    }
    List<Comment> comments = null;
    if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) {
        comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatusEnum.PUBLISHED.getCode());
    } else {
        comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatusEnum.RECYCLE.getCode());
    }
    //默认显示10条
    Integer size = 10;
    //获取每页评论条数
    if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()));
    }
    //评论分页
    ListPage<Comment> commentsPage = new ListPage<Comment>(CommentUtil.getComments(comments), cp, size);
    int[] rainbow = PageUtil.rainbow(cp, commentsPage.getTotalPage(), 3);
    model.addAttribute("is_page", true);
    model.addAttribute("post", post);
    model.addAttribute("comments", commentsPage);
    model.addAttribute("commentsCount", comments.size());
    model.addAttribute("rainbow", rainbow);
    postService.cacheViews(post.getPostId());

    //如果设置了自定义模板,则渲染自定义模板
    if (StrUtil.isNotEmpty(post.getCustomTpl())) {
        return this.render(post.getCustomTpl());
    }
    return this.render("page");
}
 
Example 10
Source File: FrontNoticeController.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 渲染公告详情
 *
 * @param postId 公告Id
 * @param model  model
 * @return 模板路径/themes/{theme}/notice
 */
@GetMapping(value = {"{postId}"})
public String getNotice(@PathVariable(value = "postId") Long postId,
                        @RequestParam(value = "page", defaultValue = "1") Integer page,
                        Model model) {
    //1、查询公告
    Post post = postService.get(postId);


    if (null == post || !post.getPostStatus().equals(PostStatusEnum.PUBLISHED.getCode())) {
        return this.renderNotFound();
    }

    //2、上一篇下一篇
    Post beforePost = postService.findPreciousPost(post.getId(), PostTypeEnum.POST_TYPE_NOTICE.getValue());
    Post afterPost = postService.findNextPost(post.getId(), PostTypeEnum.POST_TYPE_NOTICE.getValue());
    model.addAttribute("beforePost", beforePost);
    model.addAttribute("afterPost", afterPost);

    //3、评论列表
    List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.getId(), CommentStatusEnum.PUBLISHED.getCode());

    //默认显示10条
    Integer size = 10;
    //获取每页评论条数
    if (!StringUtils.isBlank(SensConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) {
        size = Integer.parseInt(SensConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()));
    }
    //评论分页
    ListPage<Comment> commentsPage = new ListPage<Comment>(CommentUtil.getComments(comments), page, size);
    int[] rainbow = PageUtil.rainbow(page, commentsPage.getTotalPage(), 10);

    //5.公告访问量
    postService.updatePostView(post.getId());

    //6、作者
    User user = userService.get(post.getUserId());
    post.setUser(user);

    //7、是否是作者
    User loginUser = getLoginUser();
    if (loginUser != null && Objects.equals(loginUser.getId(), post.getUserId())) {
        model.addAttribute("isAuthor", Boolean.TRUE);
    }

    model.addAttribute("post", post);
    model.addAttribute("comments", commentsPage);
    model.addAttribute("commentCount", comments.size());
    model.addAttribute("rainbow", rainbow);

    //侧边栏
    model.addAttribute("sidebarType", SidebarTypeEnum.NOTICE.getValue());
    model.addAttribute("noticeList", postService.findAllPosts(PostTypeEnum.POST_TYPE_NOTICE.getValue()));
    return this.render("notice");
}