コード例 #1
0
  @RequestMapping(value = "/admin/blogsearch", method = RequestMethod.GET)
  public String blogSearch(
      @RequestParam(value = "keyword", defaultValue = "") String keyword,
      @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
      ModelMap model) {

    if (keyword.equals("")) {
      ListResult<Blog> listResult = getBlogsByPage(1, 3);
      model.addAttribute("listOfBlogs", listResult.getFetchedList());
      model.addAttribute("totalPage", listResult.getTotalPage());
      model.addAttribute("currentPage", listResult.getCurrentPage());
      return "admin";
    } else {
      logger.info("enter blog search");
      SearchResult<Blog> searchResult = blogService.searchBlogByPage((pageNum - 1) * 5, 5, keyword);
      int totalCount = searchResult.getTotalCount();
      int totalPage = totalCount / 5 + (((totalCount % 5) == 0) ? 0 : 1);
      int currentPage = pageNum;
      List<Blog> listOfBlogs = searchResult.getFetchedList();
      model.addAttribute("totalPage", totalPage);
      model.addAttribute("currentPage", currentPage);
      model.addAttribute("listOfBlogs", listOfBlogs);
      model.addAttribute("keyword", keyword);
      return "blogresult";
    }
  }
コード例 #2
0
  @RequestMapping(value = "/admin", method = RequestMethod.GET)
  public String admin(
      @RequestParam(value = "page", defaultValue = "1") Integer pageNum, ModelMap model) {
    ListResult<Blog> listResult = getBlogsByPage(pageNum, 3);

    model.addAttribute("listOfBlogs", listResult.getFetchedList());
    model.addAttribute("totalPage", listResult.getTotalPage());
    model.addAttribute("currentPage", listResult.getCurrentPage());
    return "admin";
  }
コード例 #3
0
  @RequestMapping(value = "/admin/addblogaction", method = RequestMethod.POST)
  public String addblogaction(@ModelAttribute("blog") Blog blog, ModelMap model) {
    // TODO how to get blog from url??
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String name = auth.getName();
    logger.debug("name: " + name);
    blog.setInsertDate(new Timestamp(System.currentTimeMillis()));
    blog.setAuthor(name);
    blogService.insertBlog(blog);

    ListResult<Blog> listResult = getBlogsByPage(1, 3);
    model.addAttribute("listOfBlogs", listResult.getFetchedList());
    model.addAttribute("totalPage", listResult.getTotalPage());
    model.addAttribute("currentPage", listResult.getCurrentPage());
    return "admin";
  }