56. 글목록 보기
by 볼빵빵오춘기BoardController
- BoardService DI
- index() 수정한다.
@Autowired
private BoardService boardService;
@GetMapping({"","/"})
public String index( Model model, @PageableDefault(size=2,sort="id",direction = Sort.Direction.DESC)Pageable pageable){
model.addAttribute("boards",boardService.글목록(pageable));
return "index";
}
BoardService
@Transactional(readOnly = true)
public Page<Board> 글목록(Pageable pageable) {
return boardRepository.findAll(pageable);
}
index.jsp
리스트 부분 수정한다.
<ul class="pagination justify-content-center">
<c:choose>
<c:when test="${boards.first}">
<li class="page-item disabled">
<a class="page-link" href="?page=${boards.number-1}">Previous</a>
</li>
</c:when>
<c:otherwise>
<li class="page-item">
<a class="page-link" href="?page=${boards.number-1}">Previous</a>
</li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${boards.last}">
<li class="page-item disabled">
<a class="page-link" href="?page=${boards.number+1}">Next</a>
</li>
</c:when>
<c:otherwise>
<li class="page-item">
<a class="page-link" href="?page=${boards.number+1}">Next</a>
</li>
</c:otherwise>
</c:choose>
</ul>
'강의 따라하기 > blog' 카테고리의 다른 글
59. 글 삭제하기 (0) | 2024.01.04 |
---|---|
58. 글 상세보기 (1) | 2024.01.04 |
55. 글쓰기 완료 (0) | 2024.01.04 |
54. 스프링 시큐리티 로그인 (1) | 2024.01.04 |
53. XSS와 CSRF (1) | 2024.01.04 |
블로그의 정보
Hello 춘기's world
볼빵빵오춘기