Controller
//상세페이지
@RequestMapping("/notice_view")
public String notice_view(Criteria cri,@RequestParam("tno")int tno, Model model,HttpServletResponse response, HttpServletRequest request) {
//조회수-Cookie or 세션 이용해서 조회수 중복 방지
Cookie[] cookies=request.getCookies();
int countCookie=0;
for(Cookie c : cookies) {
if(c.getName().equals(Integer.toString(tno))) {
countCookie++;
}
}
if(countCookie==0) {
Cookie cookie = new Cookie(Integer.toString(tno),Integer.toString(tno));
cookie.setMaxAge(30);
response.addCookie(cookie);
tripService.hitUpdate(tno); //조회수 업데이트
}
//클릭한 글 번호에 대한 내용을 조회
TripVO vo = tripService.getContent(tno);
model.addAttribute("vo",vo);
//검색 후 상세페이지에서 다시 목록으로 넘어갔을 때 값이 유지되도록
int total=tripService.getTotal(cri);
PageVO pvo = new PageVO(cri,total);
model.addAttribute("pvo",pvo);
//이전글, 다음글
ArrayList<TripVO> list = tripService.getPrevNext(tno);
model.addAttribute("list", list);
return "trip/notice_view";
}
list.jsp에서
<td class="tit_notice"><a href="notice_view?tno=${colList.tno}&page=${pageVO.page}&amount=${pageVO.amount}&searchType=${pageVO.cri.searchType}&searchName=${pageVO.cri.searchName}">${colList.title}</a></td>
로 상세페이지에도 값을 넘기고
view.jsp에서
<a href="notice_list?page=${pvo.page}&amount=${pvo.amount}&searchType=${pvo.cri.searchType}&searchName=${pvo.cri.searchName}" class="btn_bbs">목록</a>
로 똑같이 값을 넘긴다.
=>이렇게 하면 검색한 상태가 그대로 남고, 검색한 페이지네이션의 페이지에 따라 이동할 수 있다.
가령, 검색해서 나온 데이터가 3페이지 일 때, 2페이지의 게시물 상세페이지로 이동했다가 목록버튼을 누르면 검색한 상태 그대로의 2페이지로 이동할 수 있다.
'Spring' 카테고리의 다른 글
230209 Spring 검색과 페이징 처리 (0) | 2023.02.09 |
---|---|
230208 Spring 페이징, MySQL limit함수 (1) | 2023.02.08 |
230208 Spring myweb 기능구현 다음글-이전글 (0) | 2023.02.08 |
230208 Spring myweb 기능구현-등록-목록-상세, 수정, 삭제 (0) | 2023.02.08 |
230207 Spring 타일즈 뷰 템플릿 (0) | 2023.02.07 |