示例#1
0
 @RequestMapping(
     value = "",
     method = {GET, HEAD})
 public String listPublishedPosts(Model model, @RequestParam(defaultValue = "1") int page) {
   Pageable pageRequest = PageableFactory.forLists(page);
   Page<Post> result = service.getPublishedPosts(pageRequest);
   return renderListOfPosts(result, model, "All Posts");
 }
示例#2
0
  @RequestMapping(
      value = "/{year:\\d+}/{month:\\d+}/{day:\\d+}/{slug}",
      method = {GET, HEAD})
  public String showPost(
      @PathVariable String year,
      @PathVariable String month,
      @PathVariable String day,
      @PathVariable String slug,
      Model model) {

    String publicSlug = String.format("%s/%s/%s/%s", year, month, day, slug);
    Post post = service.getPublishedPost(publicSlug);
    model.addAttribute("post", PostView.of(post, dateFactory));
    model.addAttribute("categories", PostCategory.values());
    model.addAttribute("activeCategory", post.getCategory().getDisplayName());
    model.addAttribute("disqusShortname", service.getDisqusShortname());
    return "blog/show";
  }
示例#3
0
 private String renderListOfPosts(Page<Post> page, Model model, String activeCategory) {
   Page<PostView> postViewPage = PostView.pageOf(page, dateFactory);
   List<PostView> posts = postViewPage.getContent();
   model.addAttribute("activeCategory", activeCategory);
   model.addAttribute("categories", PostCategory.values());
   model.addAttribute("posts", posts);
   model.addAttribute("paginationInfo", new PaginationInfo(postViewPage));
   model.addAttribute("disqusShortname", service.getDisqusShortname());
   return "blog/index";
 }
示例#4
0
 @RequestMapping(
     value = "/category/{category}",
     method = {GET, HEAD})
 public String listPublishedPostsForCategory(
     @PathVariable("category") PostCategory category,
     Model model,
     @RequestParam(defaultValue = "1", value = "page") int page) {
   Pageable pageRequest = PageableFactory.forLists(page);
   Page<Post> result = service.getPublishedPosts(category, pageRequest);
   return renderListOfPosts(result, model, category.getDisplayName());
 }
示例#5
0
  @RequestMapping(
      value = "/{year:\\d+}",
      method = {GET, HEAD})
  public String listPublishedPostsForYear(
      @PathVariable int year,
      @RequestParam(defaultValue = "1", value = "page") int page,
      Model model) {

    Pageable pageRequest = PageableFactory.forLists(page);
    Page<Post> result = service.getPublishedPostsByDate(year, pageRequest);
    model.addAttribute("title", String.format("Archive for %d", year));
    return renderListOfPosts(result, model, "All Posts");
  }
示例#6
0
  @RequestMapping(
      value = "/{year:\\d+}/{month:\\d+}",
      method = {GET, HEAD})
  public String listPublishedPostsForYearAndMonth(
      @PathVariable int year,
      @PathVariable int month,
      @RequestParam(defaultValue = "1", value = "page") int page,
      Model model) {

    Pageable pageRequest = PageableFactory.forLists(page);
    Page<Post> result = service.getPublishedPostsByDate(year, month, pageRequest);
    YearMonth yearMonth = new YearMonth(year, month);
    model.addAttribute("title", "Archive for " + yearMonth.toString("MMMM yyyy"));
    return renderListOfPosts(result, model, "All Posts");
  }