batis page

jyp·2023년 1월 17일
0

학원

목록 보기
28/57
post-thumbnail

Autowired 적고 체크할때 redirect 사용했으면
return해서 받는곳 requestmapping 에서 return 해줘야함

ArrayList<BoardDto> list = bdao.list();
model.addAttribute("list", list);
	
위에 두줄 코드를 한줄로
model.addAttribute("list", bdao.list()); << 이거 개편할듯

시작 page 구하고 값 넣기

int page;
	
if(request.getParameter("page")==null)
	page = 1;
else
	page = Integer.parseInt(request.getParameter("page"));
	
// 해당페이지의 start위치를 구하기
int start = (page-1)*10;
	
int pstart = page/10;

if(page%10 == 0)
pstart--;

pstart = pstart*10+1;
	
int pend = pstart+9;
	
// 총 페이지보다 pend가 클경우는 pend = chong
int chong = bdao.getChong();
System.out.println(chong);
	
if(pend > chong)
	pend = chong;
	
model.addAttribute("chong", chong);
model.addAttribute("pstart", pstart);
model.addAttribute("pend", pend);
	
ArrayList<BoardDto> list = bdao.list(start);
model.addAttribute("list", list);

1페이지,10페이지 왼쪽,오른쪽으로 이동하는 코드

<c:if test="${pstart != 1}">
	<a href="list?page=${pstart-1}"> << </a>
</c:if>
		
	<c:if test="${pstart == 1}">
		<<
	</c:if>
		
	<c:if test="${page != 1}">
		<a href="list?page=${page-1}"> < </a>
	</c:if>
		
	<c:if test="${page == 1}">
		<
	</c:if>
	
	<c:forEach begin="${pstart}" end="${pend}" var="i">	
		<c:if test="${page != i}">
			<a href="list?page=${i}"> ${i} </a>
		</c:if>
			
		<c:if test="${page == i}">
			<span style="color:red";>${i}</span>
		</c:if>
			
	</c:forEach>
		
	<c:if test="${pend != chong}">
		<a href="list?page=${page+1}"> > </a>
	</c:if>
		
	<c:if test="${page == chong}">
		>
	</c:if>
		
	<c:if test="${pend != chong}">
		<a href="list?page=${page+10}"> >> </a>
	</c:if>
	
	<c:if test="${pend == chong}">
		>>
	</c:if>
profile
국비 코딩

0개의 댓글