elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web (Moderador: #!drvy)
| | |-+  Crud en Spring Boot con Modales, Java, Spring Boot thymeleaf.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Crud en Spring Boot con Modales, Java, Spring Boot thymeleaf.  (Leído 3,335 veces)
Beginner Web


Desconectado Desconectado

Mensajes: 634


youtu.be/0YhflLRE-DA


Ver Perfil
Crud en Spring Boot con Modales, Java, Spring Boot thymeleaf.
« en: 2 Marzo 2021, 03:02 am »

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
  1.  
  2. <div th:insert="layout/header :: header"></div>
  3.  
  4. <div class="col-12">
  5. <h2>Noticias</h2>
  6. <div class="alert"></div>
  7.  
  8.  
  9. <button type="button" class="btn btn-success" data-toggle="modal"
  10. data-target="#agregarNoticiaModal">Agregar</button>
  11.  
  12. <div class="modal fade" id="agregarNoticiaModal" tabindex="-1"
  13. role="dialog" aria-labelledby="addClassModalLabel" aria-hidden="true">
  14. <div class="modal-dialog" role="document">
  15. <div class="modal-content">
  16. <div class="modal-header">
  17. <h4 class="modal-title" id="agregarNoticiaModalLabel">Agregar
  18. Noticia</h4>
  19. <button type="button" class="close" data-dismiss="modal"
  20. aria-label="Close">
  21. <span aria-hidden="true">&times;</span>
  22. </button>
  23. </div>
  24.  
  25. <div class="modal-body">
  26. <form action="#" method="POST" th:action="@{/save}"
  27. th:object="${noticia}">
  28. <div class="form-group">
  29. <label for="titulo">Titulo:</label> <input type="text"
  30. class="form-control" id="titulo" value="" th:name="titulo" />
  31. </div>
  32. <div class="form-group">
  33. <label for="descripcion">Descripcion:</label> <input type="text"
  34. class="form-control" id="descripcion" value=""
  35. th:name="descripcion" />
  36. </div>
  37.  
  38. <div class="form-group">
  39. <label for="fileUpload">Imagen:</label>
  40. <fieldset style="margin-left: 10px;">
  41. <input id="fileUpload" type="file" style="margin-left: 20px"
  42. value="" th:name="imagen" />
  43. </div>
  44.  
  45. <input type="submit" value="Aceptar" />
  46. </form>
  47. </div>
  48.  
  49. </div>
  50. </div>
  51.  
  52. </div>
  53.  
  54. <table class="table table-bordered table-responsive p-3">
  55. <thead class="thead-dark">
  56. <tr class="text-center">
  57. <th style="width: 6%">ID</th>
  58. <th>Titulo</th>
  59. <th>Descripción</th>
  60. <th style="width: 10%">Imagen</th>
  61. <th style="width: 11%">Fecha</th>
  62. <th style="width: 10%">Editar</th>
  63. <th style="width: 10%">Eliminar</th>
  64. </tr>
  65. </thead>
  66. <tr class="text-center" th:each="noticia : ${list}">
  67. <td th:text="${noticia.id}"></td>
  68. <td th:text="${noticia.titulo}"></td>
  69. <td th:text="${noticia.descripcion}"></td>
  70. <td><img class="card-img-top m-auto"
  71. th:src="${noticia.imagen}"></td>
  72. <td th:text="${noticia.fecha}"></td>
  73. <td><a class="btn btn-warning">Editar <i
  74. class="fa fa-edit"></i></a></td>
  75. <td>
  76. <form method="post">
  77. <input type="hidden" name="id" />
  78. <button type="submit" class="btn btn-danger">
  79. Eliminar <i class="fa fa-trash"></i>
  80. </button>
  81. </form>
  82. </td>
  83. </tr>
  84. </tbody>
  85. </table>
  86.  
  87. <div class="row">
  88. <div class="col-md-2"></div>
  89. <div class="col-md-8">
  90. <nav aria-label="Pagination">
  91. <ul class="pagination justify-content-center">
  92. <li class="page-item"
  93. th:classappend="${prev == 0 ? 'disabled': ''}"><a
  94. class="page-link" th:href="@{|/noticias/?page=${prev}|}">Anterior</a></li>
  95. <li class="page-item" th:each="page : ${pages}"
  96. th:classappend="${current == page ? 'active': ''}"><a
  97. class="page-link" th:href="@{|/noticias/?page=${page}|}"
  98. th:text="${page}"></a></li>
  99. <li class="page-item"
  100. th:classappend="${current == last ? 'disabled': ''}"><a
  101. class="page-link" th:href="@{|/noticias/?page=${next}|}">Siguiente</a></li>
  102. </ul>
  103. </nav>
  104. </div>
  105. <div class="col-md-2"></div>
  106. </div>
  107.  
  108. </div>
  109.  
  110.  
  111.  
  112.  
  113.  
  114. <div th:insert="layout/footer :: footer"></div>
  115. </body>

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

Código
  1. @RequestMapping(value = "/save", method = RequestMethod.POST)
  2. public String save(@ModelAttribute("noticia") Noticia noticia) {
  3. this.noticia.save(noticia);
  4. return "redirect:/";
  5. }

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



« Última modificación: 2 Marzo 2021, 04:39 am por Beginner Web » En línea

7w7
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problemita con mis urls, Java, Spring Boot thymeleaf
Desarrollo Web
Beginner Web 1 2,410 Último mensaje 1 Marzo 2021, 14:11 pm
por MinusFour
Actualizar registro de tabla usando modal con SPring Boot, Java, thymeleaf
Desarrollo Web
Beginner Web 0 3,111 Último mensaje 3 Marzo 2021, 01:46 am
por Beginner Web
spring boot crud modales
Desarrollo Web
Beginner Web 0 2,001 Último mensaje 22 Abril 2021, 20:10 pm
por Beginner Web
Spring Boot Crud
Java
thejax 2 3,133 Último mensaje 14 Mayo 2021, 05:32 am
por thejax
validad modal form en spring boot con thymeleaf
Java
Beginner Web 3 4,957 Último mensaje 24 Junio 2021, 21:43 pm
por sapito169
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines