지난 포스팅
- Controller
/**
* 전체 게시판 응답 함수 (조회순 정렬)
* @param pageable
* @return
*/
@GetMapping("/api/board")
public ResponseEntity<?> getAllBoard(
@PageableDefault(size = 10,sort = "viewCnt",direction = Sort.Direction.DESC) Pageable pageable) {
Page<AllBoradResponseDTO> allBoradResponseDTOList = boardService.allBoard(pageable);
return ResponseEntity.ok(allBoradResponseDTOList);
}
@PageableDefault에 size = 10 (디폴트가 10이라 10은 따로 안해도 됨) OrderBy는 BoardEntity 테이블의 속성 값인 viewCnt로 sort값을 부여한다.
- Service
/**
* 전체 게시판 응답 함수
* @param pageable
* @return
*/
@Override
public Page<AllBoradResponseDTO> allBoard(Pageable pageable) {
Page<BoardEntity> boardEntity = boardRepository.findAll(pageable);
Page<AllBoradResponseDTO> allBoradResponseDTO = boardEntity.map(
board -> AllBoradResponseDTO.builder()
.board_id(board.getId())
.title(board.getTitle())
.viewCnt(board.getViewCnt())
.writer(board.getUserInfoEntity().getNickname())
.createdDate(board.getCreatedDate())
.build()
);
return allBoradResponseDTO;
}
지난번 포스팅에서 조금 수정을 한 결과이다
응답이 제대로 되는것을 확인 할 수 있다 :)
'JAVA' 카테고리의 다른 글
SpringBoot thymeleaf Ajax 비통기 통신 parsererror 이슈 해결 (0) | 2022.09.08 |
---|---|
Spring Boot 게시판 및 댓글 출력 (thymeleaf, ajax) JPA 양방향 매핑 (0) | 2022.09.06 |
Spring Boot, thymeleaf ajax로그인 요청 (javascript) (0) | 2022.09.03 |
Spring Boot 게시판 상세내용 조회 구현 (0) | 2022.08.31 |
Spring Boot 기본적인 전체 게시판 게시판 응답 (0) | 2022.08.31 |
댓글