728x90
Controller
//작성글 조회
@GetMapping("/space/{curPage}")
public PagingResult readBoard(@PathVariable Integer curPage) {
return registryService.getBoards(curPage);
}
RegistryService
public PagingResult getBoards(int curPage) {
Pageable pageable = PageRequest.of(curPage-1, PAGE_POST_COUNT);
Page<Registry> boards = registryRepository.findAllByOrderByCreatedAtDesc(pageable);
List<Registry> boardList = boards.getContent();
return new PagingResult(boardList, boards.getTotalPages());
}
RegistryRepository
public interface RegistryRepository extends JpaRepository<Registry, Long> {
Page<Registry> findAllByOrderByCreatedAtDesc(Pageable pageable);
}
PagingResult
@Data
@AllArgsConstructor
public class PagingResult<T> {
private T data;
private int count;
}
참고 링크
front : https://github.com/slcommunity/til-front/blob/main/js/boardList.js
backend :
728x90
'Project' 카테고리의 다른 글
프로젝트 관련 정리글 링크 첨부 (0) | 2022.03.27 |
---|---|
웹 소켓 구현 과정 (0) | 2022.03.24 |
3차 프로젝트_KPT 회고 (0) | 2021.12.13 |
3차 프로젝트_기획안 수정 (0) | 2021.11.22 |
3차 프로젝트 _ S.A(Starting Assignment) (0) | 2021.11.19 |