Browse Source

Create

master
Juanjo 1 year ago
parent
commit
1994e55a75
3 changed files with 49 additions and 3 deletions
  1. +4
    -2
      src/main/java/es/fp/edu/conecta2/controladores/WebControlador.java
  2. +1
    -1
      src/main/resources/templates/menu/m1.html
  3. +44
    -0
      src/main/resources/templates/nuevo_usuario.html

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

@ -1,6 +1,7 @@
package es.fp.edu.conecta2.controladores; package es.fp.edu.conecta2.controladores;
import es.fp.edu.conecta2.modelo.user.User;
import es.fp.edu.conecta2.servicios.UserService; import es.fp.edu.conecta2.servicios.UserService;
import io.micrometer.common.util.StringUtils; import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -25,8 +26,9 @@ public class WebControlador {
@GetMapping ("/nuevo") @GetMapping ("/nuevo")
public String nuevoUser(Model modelo){ public String nuevoUser(Model modelo){
modelo.addAttribute("user",servicioUser.listarUser());
return "usuarios";
User usuario = new User();
modelo.addAttribute("user",usuario);
return "nuevo_usuario";
} }
@GetMapping ("/borrar") @GetMapping ("/borrar")


+ 1
- 1
src/main/resources/templates/menu/m1.html View File

@ -27,7 +27,7 @@
CRUD CRUD
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Crear</a></li>
<li><a class="dropdown-item" href="nuevo">Crear</a></li>
<li><a class="dropdown-item" href="#">Actualiazar</a></li> <li><a class="dropdown-item" href="#">Actualiazar</a></li>
<li><a class="dropdown-item" href="#">Borrar</a></li> <li><a class="dropdown-item" href="#">Borrar</a></li>
</ul> </ul>


+ 44
- 0
src/main/resources/templates/nuevo_usuario.html View File

@ -0,0 +1,44 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="es"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{head/head :: mihead}"></head>
<body class="d-flex flex-column h-100">
<header th:replace="~{menu/m1 :: usuarios}"></header>
<div class="p-5 mb-4 bg-light rounded-3">
<div class="container-fluid py-5">
<h1 class="display-5 fw-bold">Nuevo usuario</h1>
<p class="col-md-8 fs-4">Ejemplo de CRUD</p>
<a class="btn btn-lg btn-primary" href="https://2dam.fp.edu.es/gitea/conecta2">Código fuente</a>
</div>
</div>
<main>
<div class="container">
<form th:action="@{/}" th:object="${user}" method="post">
<table class="table table-sm">
<thead>
<tr>
<th scope="col">#idUsuario</th>
<th scope="col">Nombres</th>
<th scope="col"></th>
</thead>
<tbody>
<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>
</div>
</main>
<footer th:replace="~{foot/javascript :: javascript}"></footer>
</body>
</html>

Loading…
Cancel
Save