Crud en Spring Boot con Modales, Java, Spring Boot thymeleaf.

Iniciado por Beginner Web, 2 Marzo 2021, 03:02 AM

0 Miembros y 1 Visitante están viendo este tema.

Beginner Web

Hola, estoy intentando hacer un CRUD con las tecnologías mencionadas en el titulo pero no se que pasa, me sale error al cargar la página. este es mi html.

Código (html4strict) [Seleccionar]
<body>

<div th:insert="layout/header :: header"></div>

<div class="col-12">
<h2>Noticias</h2>
<div class="alert"></div>


<button type="button" class="btn btn-success" data-toggle="modal"
data-target="#agregarNoticiaModal">Agregar</button>

<div class="modal fade" id="agregarNoticiaModal" tabindex="-1"
role="dialog" aria-labelledby="addClassModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="agregarNoticiaModalLabel">Agregar
Noticia</h4>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body">
<form action="#" method="POST" th:action="@{/save}"
th:object="${noticia}">
<div class="form-group">
<label for="titulo">Titulo:</label> <input type="text"
class="form-control" id="titulo" value="" th:name="titulo" />
</div>
<div class="form-group">
<label for="descripcion">Descripcion:</label> <input type="text"
class="form-control" id="descripcion" value=""
th:name="descripcion" />
</div>

<div class="form-group">
<label for="fileUpload">Imagen:</label>
<fieldset style="margin-left: 10px;">
<input id="fileUpload" type="file" style="margin-left: 20px"
value="" th:name="imagen" />
</fieldset>
</div>

<input type="submit" value="Aceptar" />
</form>
</div>

</div>
</div>

</div>

<table class="table table-bordered table-responsive p-3">
<thead class="thead-dark">
<tr class="text-center">
<th style="width: 6%">ID</th>
<th>Titulo</th>
<th>Descripción</th>
<th style="width: 10%">Imagen</th>
<th style="width: 11%">Fecha</th>
<th style="width: 10%">Editar</th>
<th style="width: 10%">Eliminar</th>
</tr>
</thead>
<tbody>
<tr class="text-center" th:each="noticia : ${list}">
<td th:text="${noticia.id}"></td>
<td th:text="${noticia.titulo}"></td>
<td th:text="${noticia.descripcion}"></td>
<td><img class="card-img-top m-auto"
th:src="${noticia.imagen}"></td>
<td th:text="${noticia.fecha}"></td>
<td><a class="btn btn-warning">Editar <i
class="fa fa-edit"></i></a></td>
<td>
<form method="post">
<input type="hidden" name="id" />
<button type="submit" class="btn btn-danger">
Eliminar <i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
</tbody>
</table>

<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<nav aria-label="Pagination">
<ul class="pagination justify-content-center">
<li class="page-item"
th:classappend="${prev == 0 ? 'disabled': ''}"><a
class="page-link" th:href="@{|/noticias/?page=${prev}|}">Anterior</a></li>
<li class="page-item" th:each="page : ${pages}"
th:classappend="${current == page ? 'active': ''}"><a
class="page-link" th:href="@{|/noticias/?page=${page}|}"
th:text="${page}"></a></li>
<li class="page-item"
th:classappend="${current == last ? 'disabled': ''}"><a
class="page-link" th:href="@{|/noticias/?page=${next}|}">Siguiente</a></li>
</ul>
</nav>
</div>
<div class="col-md-2"></div>
</div>

</div>





<div th:insert="layout/footer :: footer"></div>
</body>


Y los métodos de mi controlador para guardar son estos:

Código (java) [Seleccionar]
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@ModelAttribute("noticia") Noticia noticia) {
this.noticia.save(noticia);
return "redirect:/";
}


Que puede ser? Tambien sucede que cuando hago un alta me redirecciona al /index , cuando debería ser a /noticias :(

7w7