Search in sources :

Example 1 with Archive

use of cc.ryanc.halo.model.dto.Archive in project halo by ruibaby.

the class PostServiceImpl method findPostGroupByPostDate.

/**
 * 查询归档信息
 *
 * @return List
 */
@Override
public List<Archive> findPostGroupByPostDate() {
    List<Object[]> objects = postRepository.findPostGroupByDate();
    List<Archive> archives = new ArrayList<>();
    Archive archive = null;
    for (Object[] obj : objects) {
        archive = new Archive();
        archive.setYear(obj[0].toString());
        archive.setMonth(obj[1].toString());
        archive.setCount(obj[2].toString());
        archive.setPosts(this.findPostByYearAndMonth(obj[0].toString(), obj[1].toString()));
        archives.add(archive);
    }
    return archives;
}
Also used : Archive(cc.ryanc.halo.model.dto.Archive) ArrayList(java.util.ArrayList)

Example 2 with Archive

use of cc.ryanc.halo.model.dto.Archive in project halo by ruibaby.

the class IndexController method index.

/**
 * 首页分页
 *
 * @param model model
 * @param page page
 * @param size size
 * @return freemarker
 */
@GetMapping(value = "page/{page}")
public String index(Model model, @PathVariable(value = "page") Integer page) {
    Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    // 默认显示10条
    Integer size = 10;
    // 尝试加载设置选项,用于设置显示条数
    if (!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))) {
        size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
    }
    // 所有文章数据,分页
    Pageable pageable = new PageRequest(page - 1, size, sort);
    Page<Post> posts = postService.findPostByStatus(0, pageable);
    model.addAttribute("posts", posts);
    // 文章总数
    model.addAttribute("postsCount", postService.findAllPosts().size());
    model.addAttribute("is_home", true);
    // 用户信息
    User user = userService.findUser();
    model.addAttribute("user", user);
    // 所有分类目录
    List<Category> categories = categoryService.findAllCategories();
    model.addAttribute("categories", categories);
    // 菜单列表
    List<Menu> menus = menuService.findAllMenus();
    model.addAttribute("menus", menus);
    // 归档数据,包含[year,month,count,List<Post>]
    List<Archive> archives = postService.findPostGroupByPostDate();
    model.addAttribute("archives", archives);
    // 设置选项
    model.addAttribute("options", HaloConst.OPTIONS);
    return this.render("index");
}
Also used : Archive(cc.ryanc.halo.model.dto.Archive) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort)

Example 3 with Archive

use of cc.ryanc.halo.model.dto.Archive in project halo by ruibaby.

the class IndexController method archives.

/**
 * 文章归档,根据年月
 *
 * @param model model
 * @param year year
 * @param month month
 * @return string
 */
@GetMapping(value = "/archives/{year}/{month}")
public String archives(Model model, @PathVariable(value = "year") String year, @PathVariable(value = "month") String month) {
    log.info(year);
    log.info(month);
    // 根据年月查出的文章数据,分页
    Sort sort = new Sort(Sort.Direction.DESC, "post_date");
    Pageable pageable = new PageRequest(0, 5, sort);
    Page<Post> posts = postService.findPostByYearAndMonth(year, month, pageable);
    model.addAttribute("posts", posts);
    // 文章总数
    model.addAttribute("postsCount", postService.findAllPosts().size());
    // 用户信息
    User user = userService.findUser();
    model.addAttribute("user", user);
    // 分类目录
    List<Category> categories = categoryService.findAllCategories();
    model.addAttribute("categories", categories);
    // 菜单列表
    List<Menu> menus = menuService.findAllMenus();
    model.addAttribute("menus", menus);
    // 归档数据,包含[year,month,count,List<Post>]
    List<Archive> archives = postService.findPostGroupByPostDate();
    model.addAttribute("archives", archives);
    // 是否是归档页,用于判断输出链接
    model.addAttribute("isArchives", "true");
    // 设置选项
    model.addAttribute("options", HaloConst.OPTIONS);
    return this.render("archives");
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Archive(cc.ryanc.halo.model.dto.Archive) Sort(org.springframework.data.domain.Sort)

Example 4 with Archive

use of cc.ryanc.halo.model.dto.Archive in project halo by ruibaby.

the class IndexController method archives.

/**
 * 文章归档分页
 *
 * @param model model
 * @param page page
 * @return string
 */
@GetMapping(value = "/archives/page/{page}")
public String archives(Model model, @PathVariable(value = "page") Integer page) {
    // 所有文章数据,分页,material主题适用
    Sort sort = new Sort(Sort.Direction.DESC, "postDate");
    Pageable pageable = new PageRequest(page - 1, 5, sort);
    Page<Post> posts = postService.findPostByStatus(0, pageable);
    model.addAttribute("posts", posts);
    // 文章总数
    model.addAttribute("postsCount", postService.findAllPosts().size());
    model.addAttribute("is_archives", true);
    // 包含[List<Post>,year,month,count]
    List<Archive> archives = postService.findPostGroupByPostDate();
    model.addAttribute("archives", archives);
    // 用户信息
    User user = userService.findUser();
    model.addAttribute("user", user);
    // 菜单列表
    List<Menu> menus = menuService.findAllMenus();
    model.addAttribute("menus", menus);
    // 所有分类目录
    List<Category> categories = categoryService.findAllCategories();
    model.addAttribute("categories", categories);
    // 是否是归档页,用于判断输出链接
    model.addAttribute("isArchives", "true");
    // 设置选项
    model.addAttribute("options", HaloConst.OPTIONS);
    return this.render("archives");
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Archive(cc.ryanc.halo.model.dto.Archive) Sort(org.springframework.data.domain.Sort)

Aggregations

Archive (cc.ryanc.halo.model.dto.Archive)4 PageRequest (org.springframework.data.domain.PageRequest)3 Pageable (org.springframework.data.domain.Pageable)3 Sort (org.springframework.data.domain.Sort)3 ArrayList (java.util.ArrayList)1