Esempio n. 1
0
  @RequestMapping(value = "/{username}", method = RequestMethod.GET)
  public String showSpitterProfile(@PathVariable String username, Model model) {
    if (!model.containsAttribute("spitter")) {
      model.addAttribute(repository.findByUsername(username));
    }

    return "profile";
  }
Esempio n. 2
0
  @RequestMapping(value = "/register", method = RequestMethod.POST)
  public String processRegistration(
      @Valid SpitterForm spitterForm, RedirectAttributes model, Errors errors)
      throws IllegalStateException, IOException {
    if (errors.hasErrors()) {
      return "registerForm";
    }
    Spitter sp = spitterForm.toSpitter();
    MultipartFile profilePic = spitterForm.getProfilePicture();
    if (profilePic != null) {
      profilePic.transferTo(new File("/data/spittr/" + sp.getUsername() + ".jpg"));
    }
    repository.save(sp);
    model.addAttribute("username", sp.getUsername());
    // model.addAttribute("spitterId", sp.getId());
    model.addFlashAttribute("spitter", sp);

    return "redirect:/spitter/{username}";
  }