예제 #1
0
 @RequestMapping("/userpage")
 public String starpage(Model model, @RequestParam(value = "page", defaultValue = "1") int page) {
   Page<Post> postsPage = postsService.getPosts(page, 5); // 5 постів на сторінку
   model.addAttribute("posts", postsPage.getContent());
   model.addAttribute("pagesCount", postsPage.getTotalPages());
   model.addAttribute("currentPage", page);
   model.addAttribute("currentUser", User.getCurrentUser());
   model.addAttribute("user", User.getCurrentUser());
   return "user_page";
 }
예제 #2
0
  @RequestMapping(value = "/userprofile", method = RequestMethod.GET)
  public String userProfile(
      Model model, @RequestParam(value = "user_id", defaultValue = "") String userId) {
    Long id = 0L;
    boolean parsingSucces = true;
    if (userId.length() > 0) {
      try {
        id = Long.parseLong(userId);
        if (usersService.getUser(id) == null) id = User.getCurrentUser().getId();
      } catch (NumberFormatException numFormatException) {
        parsingSucces = false;
      }
    }
    if (!parsingSucces || userId.length() == 0) id = User.getCurrentUser().getId();

    model.addAttribute("user", usersService.getUser(id));
    model.addAttribute("current_user_id", User.getCurrentUser().getId());
    return "user_profile";
  }
예제 #3
0
 @RequestMapping("/list")
 public String list(Model model, @RequestParam(value = "page", defaultValue = "1") int page) {
   System.out.println("before get posts");
   Page<Post> postsPage = postsService.getAllPosts(page, 5); // 5 постів на сторінку
   model.addAttribute("posts", postsPage.getContent());
   model.addAttribute("pagesCount", postsPage.getTotalPages());
   model.addAttribute("currentPage", page);
   model.addAttribute("currentUser", User.getCurrentUser());
   return "list";
 }
예제 #4
0
 @RequestMapping(value = "/storeuserinfo", method = RequestMethod.POST)
 public String storeUserInfo(
     HttpServletRequest request,
     @RequestParam(value = "address", defaultValue = "") String address,
     @RequestParam(value = "phone", defaultValue = "") String phone,
     @RequestParam(value = "fullName", defaultValue = "") String fullName,
     @RequestParam(value = "gender", defaultValue = "") Gender gender) {
   User u = User.getCurrentUser();
   u.setAddress(address);
   u.setPhone(phone);
   u.setFullName(fullName);
   u.setGender(gender);
   usersService.updateUserInfo(u);
   String referer = request.getHeader("Referer");
   return "redirect:" + referer;
 }