Browse Source

Create - controlardor Guardar

master
Juanjo 1 year ago
parent
commit
15d132a8f3
2 changed files with 9 additions and 8 deletions
  1. +6
    -3
      src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java
  2. +3
    -5
      src/main/resources/templates/nuevo_usuario.html

+ 6
- 3
src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java View File

@ -7,9 +7,7 @@ import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
@Controller
@ -30,6 +28,11 @@ public class WebControlador {
modelo.addAttribute("user",usuario);
return "nuevo_usuario";
}
@PostMapping("/guardar")
public String guardarUser (@ModelAttribute("user") User usuario) {
servicioUser.registrar(usuario);
return "redirect:/";
}
@GetMapping ("/borrar")
public String borrarUser(Model modelo){


+ 3
- 5
src/main/resources/templates/nuevo_usuario.html View File

@ -16,7 +16,7 @@
<main>
<div class="container">
<form th:action="@{/}" th:object="${user}" method="post">
<form th:action="@{/guardar}" th:object="${user}" method="post">
<table class="table table-sm">
<thead>
<tr>
@ -25,11 +25,9 @@
<th scope="col"></th>
</thead>
<tbody>
<th><input type="text" name="idUsuario" th:field="${user.idUsuario}" class="form-control" placeholder="Nº de usuario" required></th>
<td><input type="text" name="nombres" th:field="${user.nombres}" class="form-control" placeholder="Nombre y apellidos" required></td>
<th><input type="text" name="idUsuario" th:field="*{idUsuario}" class="form-control" placeholder="Nº de usuario" required></th>
<td><input type="text" name="nombres" th:field="*{nombres}" class="form-control" placeholder="Nombre y apellidos" required></td>
<td><button class="btn btn-success" >CREAR</button></td>
</tbody>
</table>
</form>


Loading…
Cancel
Save