Foro de elhacker.net

Programación => Desarrollo Web => Mensaje iniciado por: Beginner Web en 3 Marzo 2021, 06:45 am



Título: Spring MVC, problema de redireccionamiento despues de submit un modal
Publicado por: Beginner Web en 3 Marzo 2021, 06:45 am
Hola, pasa que cuando hago un CRUD al confirmar el modal me redirije al index, como hago para que se fije en la misma pagina donde estaba? Estoy usando pagination.

Por ejemplo en el borrar...

Código
  1. <td>
  2. <td><a data-toggle="modal" data-target="#removeModalNoticias"
  3. class="btn btn-danger delBtn"
  4. th:attr="data-target='#removeModalNoticias'+${noticia.id}">Eliminar
  5. <i class="fa fa-trash"></i>
  6. </a> <!-- #Modal for removing noticias -->
  7. <div class="modal fade" th:id="removeModalNoticias+${noticia.id}"
  8. id="removeModalNoticias" tabindex="-1" role="dialog"
  9. aria-labelledby="removeModalCenterTitle" aria-hidden="true">
  10. <div class="modal-dialog modal-dialog-centered" role="document">
  11. <div class="modal-content">
  12. <div class="modal-header">
  13. <h4 class="modal-title" id="removeModalCenterTitle">Eliminar
  14. Noticia</h4>
  15. <button type="button" class="close" data-dismiss="modal"
  16. aria-label="Close">
  17. <span aria-hidden="true">&times;</span>
  18. </button>
  19. </div>
  20. <div class="modal-body">
  21. <p class="alert alert-danger">Are You sure You want to
  22. delete this Noticia?</p>
  23. </div>
  24. <div class="modal-footer">
  25. <button type="button" class="btn btn-secondary"
  26. data-dismiss="modal">Close</button>
  27. <a th:href="@{/delete/(id=${noticia.id})}"
  28. class="btn btn-danger" id="delRef">Delete</a>
  29. </div>
  30. </div>
  31. </div>
  32. </div></td>
  33. </td>

Y en el Controller...

Código
  1. @GetMapping("/delete/{id}")
  2. public String delete(Long id) {
  3. noticia.deleteById(id);
  4. return "redirect://noticias";
  5. }

Y el listar con pagination buenooo...

Código
  1. @GetMapping(value = "/noticias")
  2. public String findAll(@RequestParam Map<String, Object> params, Model model) {
  3.  
  4. int page = params.get("page") != null ? Integer.valueOf(params.get("page").toString()) - 1 : 0;
  5.  
  6. PageRequest pageRequest = PageRequest.of(page, 5);
  7.  
  8. Page<Noticia> pageNoticia = noticia.findAll(pageRequest);
  9.  
  10. int totalPage = pageNoticia.getTotalPages();
  11.  
  12. if (totalPage > 0) {
  13. List<Integer> pages = IntStream.rangeClosed(1, totalPage).boxed().collect(Collectors.toList());
  14. model.addAttribute("pages", pages);
  15. }
  16.  
  17. model.addAttribute("list", pageNoticia.getContent());
  18. model.addAttribute("current", page + 1);
  19. model.addAttribute("next", page + 2);
  20. model.addAttribute("prev", page);
  21. model.addAttribute("last", totalPage);
  22.  
  23. return "noticias";
  24. }

Me ayudan?   :huh: