@TransactionalpublicList<BoardDto>getBoardlist(IntegerpageNum){Page<BoardEntity>page=boardRepository.findAll(PageRequest.of(pageNum-1,PAGE_POST_COUNT,Sort.by(Sort.Direction.ASC,"createdDate")));List<BoardEntity>boardEntities=page.getContent();List<BoardDto>boardDtoList=newArrayList<>();for(BoardEntityboardEntity:boardEntities){boardDtoList.add(this.convertEntityToDto(boardEntity));}returnboardDtoList;}@TransactionalpublicLonggetBoardCount(){returnboardRepository.count();}publicInteger[]getPageList(IntegercurPageNum){Integer[]pageList=newInteger[BLOCK_PAGE_NUM_COUNT];// 총 게시글 갯수DoublepostsTotalCount=Double.valueOf(this.getBoardCount());// 총 게시글 기준으로 계산한 마지막 페이지 번호 계산 IntegertotalLastPageNum=(int)(Math.ceil((postsTotalCount/PAGE_POST_COUNT)));// 현재 페이지를 기준으로 블럭의 마지막 페이지 번호 계산IntegerblockLastPageNum=(totalLastPageNum>curPageNum+BLOCK_PAGE_NUM_COUNT)?curPageNum+BLOCK_PAGE_NUM_COUNT:totalLastPageNum;// 페이지 시작 번호 조정curPageNum=(curPageNum<=3)?1:curPageNum-2;// 페이지 번호 할당for(intval=curPageNum,idx=0;val<=blockLastPageNum;val++,idx++){pageList[idx]=val;}returnpageList;}
댓글남기기