Update UserController.java
This commit is contained in:
parent
43fad6ba95
commit
a34be087d9
|
@ -23,6 +23,12 @@ public class UserController {
|
|||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@GetMapping("/index")
|
||||
public String userList(User user) {
|
||||
model.addAttribute("users", userRepository.findAll());
|
||||
return "index";
|
||||
}
|
||||
|
||||
@GetMapping("/signup")
|
||||
public String showSignUpForm(User user) {
|
||||
return "add-user";
|
||||
|
@ -35,7 +41,6 @@ public class UserController {
|
|||
}
|
||||
|
||||
userRepository.save(user);
|
||||
model.addAttribute("users", userRepository.findAll());
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
|
@ -43,6 +48,7 @@ public class UserController {
|
|||
public String showUpdateForm(@PathVariable("id") long id, Model model) {
|
||||
User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id));
|
||||
model.addAttribute("user", user);
|
||||
|
||||
return "update-user";
|
||||
}
|
||||
|
||||
|
@ -54,7 +60,7 @@ public class UserController {
|
|||
}
|
||||
|
||||
userRepository.save(user);
|
||||
model.addAttribute("users", userRepository.findAll());
|
||||
|
||||
return "redirect:/index";
|
||||
}
|
||||
|
||||
|
@ -62,7 +68,7 @@ public class UserController {
|
|||
public String deleteUser(@PathVariable("id") long id, Model model) {
|
||||
User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id));
|
||||
userRepository.delete(user);
|
||||
model.addAttribute("users", userRepository.findAll());
|
||||
return "index";
|
||||
|
||||
return "redirect:/index";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue