팀프로젝트/SpringBoot

스프링부트 팀플) 20240319_이전글/다음글

일일일코_장민기 2024. 3. 19. 12:33
728x90

https://offbyone.tistory.com/367

 

JSTL - <c:if>, <c:choose> 태그 사용법

jstl에서 조건에 따른 분기를 처리할 수 있는 태그로 와 가 있습니다. 1. 태그 test 속성내의 EL 의 결과가 참이면 실행됩니다. else 구문은 없습니다. 위의 코드는 변수 name의 값이 "홍길동" 이면 출력

offbyone.tistory.com

 

 

글 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>

- 서브쿼리를 통해 현재 글에서 가장 가까운 글들을 검색하고, 그 번호에 맞는 정보를 출력

 

 

 

 

기본적인 출력

 

 

가장 최신글/마지막 글은 이전글/다음글이 출력되지 않음