Browse Source

editaUser

master
Juanjo 1 year ago
parent
commit
9b3a8a404a
3 changed files with 7 additions and 2 deletions
  1. +2
    -1
      src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java
  2. +3
    -1
      src/main/java/es/fp/edu/conecta2/servicios/UserService.java
  3. +2
    -0
      src/main/resources/templates/editar_usuario.html

+ 2
- 1
src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java View File

@ -37,13 +37,14 @@ public class WebControlador {
@RequestMapping ("/editar/{num}") @RequestMapping ("/editar/{num}")
public String editarUser(@PathVariable int num, Model modelo){ public String editarUser(@PathVariable int num, Model modelo){
modelo.addAttribute("user",
modelo.addAttribute("user",
servicioUser.buscarId(num).get()); servicioUser.buscarId(num).get());
return "editar_usuario"; return "editar_usuario";
} }
@PostMapping ("/actualizar") @PostMapping ("/actualizar")
public String actualizaUser(@ModelAttribute("user") User usuario){ public String actualizaUser(@ModelAttribute("user") User usuario){
servicioUser.guardarId(usuario); servicioUser.guardarId(usuario);
return "redirect:/"; return "redirect:/";


+ 3
- 1
src/main/java/es/fp/edu/conecta2/servicios/UserService.java View File

@ -25,12 +25,14 @@ public class UserService {
public Optional<User> buscarId(Integer id){ public Optional<User> buscarId(Integer id){
return Optional.of(repo.findById(id).get()); return Optional.of(repo.findById(id).get());
} }
public void guardarId(User t) { public void guardarId(User t) {
repo.actualizaId(t.getIdUsuario(),t.getNombres());
int i = repo.actualizaId(t.getIdUsuario(), t.getNombres());
} }
} }

+ 2
- 0
src/main/resources/templates/editar_usuario.html View File

@ -15,6 +15,7 @@
</div> </div>
<main> <main>
<div class="container"> <div class="container">
<form th:action="@{/actualizar}" th:object="${user}" method="post"> <form th:action="@{/actualizar}" th:object="${user}" method="post">
<table class="table table-sm"> <table class="table table-sm">
@ -32,6 +33,7 @@
</table> </table>
</form> </form>
</div> </div>
</main> </main>


Loading…
Cancel
Save