Por ejemplo en el borrar...
Código
<td> class="btn btn-danger delBtn" th:attr="data-target='#removeModalNoticias'+${noticia.id}">Eliminar </a> <!-- #Modal for removing noticias --> <div class="modal fade" th:id="removeModalNoticias+${noticia.id}" id="removeModalNoticias" tabindex="-1" role="dialog" aria-labelledby="removeModalCenterTitle" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-content"> <div class="modal-header"> <h4 class="modal-title" id="removeModalCenterTitle">Eliminar Noticia</h4> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> </button> </div> <div class="modal-body"> <p class="alert alert-danger">Are You sure You want to delete this Noticia?</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <a th:href="@{/delete/(id=${noticia.id})}" class="btn btn-danger" id="delRef">Delete</a> </div> </div> </div> </td>
Y en el Controller...
Código
@GetMapping("/delete/{id}") noticia.deleteById(id); return "redirect://noticias"; }
Y el listar con pagination buenooo...
Código
@GetMapping(value = "/noticias") PageRequest pageRequest = PageRequest.of(page, 5); Page<Noticia> pageNoticia = noticia.findAll(pageRequest); int totalPage = pageNoticia.getTotalPages(); if (totalPage > 0) { List<Integer> pages = IntStream.rangeClosed(1, totalPage).boxed().collect(Collectors.toList()); model.addAttribute("pages", pages); } model.addAttribute("list", pageNoticia.getContent()); model.addAttribute("current", page + 1); model.addAttribute("next", page + 2); model.addAttribute("prev", page); model.addAttribute("last", totalPage); return "noticias"; }
Me ayudan?