https://offbyone.tistory.com/367
글 jsp
<c:if test="${prev != null}">
<p>
이전 글:
글번호: ${prev.boardNum} | 카테고리: ${prev.category} |
제목: <span onclick="submitForm(${prev.boardNum})">${prev.title}</span> |
닉네임: ${prev.nickname} |
작성 날짜: ${prev.edittedDate} |
조회수: ${prev.viewCount} |
추천수: ${prev.recommendNum}
</p>
</c:if>
<c:if test="${next != null}">
<p>
다음 글:
글번호: ${next.boardNum} | 카테고리: ${next.category} |
제목: <span onclick="submitForm(${next.boardNum})">${next.title}</span> |
닉네임: ${next.nickname} |
작성 날짜: ${next.edittedDate} |
조회수: ${next.viewCount} |
추천수: ${next.recommendNum}
</p>
</c:if>
컨트롤러
//현재 글의 이전 글 보기
public DebugBoardDTO prevPost(int boardNum) {
DebugBoardDTO prevPost = serv.prevPost(boardNum);
System.out.println("prevPost "+ prevPost);
return prevPost;
}
//현재 글의 다음 글 보기
public DebugBoardDTO nextPost(int boardNum) {
DebugBoardDTO nextPost = serv.nextPost(boardNum);
System.out.println("nextPost "+ nextPost);
return nextPost;
}
이걸 게시판 글 보기 메서드에 집어넣는다
매퍼
<!-- 현재 글의 이전 글 목록 -->
<select id="prevPost" parameterType="int" resultType="DebugBoardDTO">
select boardNum, nickname, title, category, edittedDate, viewCount, recommendNum
from debugboarddb
where boardNum =(
select max(boardnum)
from debugboarddb
where #{boardnum} > boardNum
)
</select>
<!-- 현재 글의 다음 글 목록 -->
<select id="nextPost" parameterType="int" resultType="DebugBoardDTO">
select boardNum, nickname, title, category, edittedDate, viewCount, recommendNum
from debugboarddb
where boardNum =(
select min(boardnum)
from debugboarddb
where boardnum > #{boardnum}
)
</select>
- 서브쿼리를 통해 현재 글에서 가장 가까운 글들을 검색하고, 그 번호에 맞는 정보를 출력
'팀프로젝트 > SpringBoot' 카테고리의 다른 글
스프링부트 팀플) 20240319 사용자가 게시판 접속 시 랜덤값 생성 (0) | 2024.03.19 |
---|---|
스프링부트 팀플) 20240319 카테고리 검색 / 검색창 (0) | 2024.03.19 |
스프링부트 팀플) 20240318_수정/삭제 비밀번호 확인 + 삭제 경고창 + 정렬 (0) | 2024.03.18 |
스프링부트 팀플) 20240318_ckEditor로 전환 + 일부 수정 (0) | 2024.03.18 |
스프링 부트 팀플) 20240317_게시판 글 수정 / 글 삭제 / 추천 증감 / 카테고리 include (0) | 2024.03.17 |