본문 바로가기

하루정리

2022.04.22 게시글 수정 삭제 페이징

 

UUid : 업로드 되는 파일에 고유한 이름을 붙여넣어 파일의 중복을 막기 위해서 사용했다.

이렇게 하면 업로드 되는 파일마다 앞에 코딩해준 이름이 붙는다. 

인터넷에서 파일을 다운받았을 때 이름이 길고 이상한 것들이 있는데 이 경우이다

 

페이징 처리를 위한 방법

페이징처리 메소드를 사용하기 위해서는  먼저 새로운 DTO를 만들어 줘야 한다.

그리고 나서 컨트롤러 서비스 mapper로 넘어가 작업을 한다. 

컨트롤러이다.  서비스이다

서비스는 길어서 둘로 나눠 찍었고 아래쪽 paging로 선언해준 값들이 jsp에서도 쓰이게 될 것이다. 당연히

새로 만들어준 dto에서 선언해준 값이 쓰인다.

 

아래부터는 jsp에서 코딩해준 코드이다. 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>게시글 페이징 처리</title>
</head>
<body>
<form action ="pagingList" method ="get">
<p>한 페이지에 출력할 게시글 갯수</p>

<c:if test ="${paging.limit ==3}" > 
<select name= "limit">
<option value="3" selected>3</option>
<option value="5">5</option>
<option value="10">10</option>

</select>
</c:if>
<c:if test ="${paging.limit ==5}" > 
<select name= "limit">
<option value="3" >3</option>
<option value="5"selected>5</option>
<option value="10">10</option>

</select>
</c:if>
<c:if test ="${paging.limit ==10}" > 
<select name= "limit">
<option value="3" >3</option>
<option value="5">5</option>
<option value="10"selected>10</option>

</select>
</c:if>
<input type ="submit" value="선택">


</form>

<table>
<tr>
<th>글번호</th>
<th>제목</th>
<th>작성자</th>
<th>작성일자</th>
<th>조회수</th>
</tr>

<c:forEach var="pl" items="${plist}">

<tr>
<th>${pl.bNum}</th>
<th><a href="boardView?bNum=${pl.bNum}"> ${pl.bTitle}</a></th>

<th>${pl.bWriter}</th>
<th>${pl.vDate}</th>
<th>${pl.bHit}</th>

</tr>
</c:forEach>

</table>

<!-- 페이징 처리  -->



<!-- 이전 버튼에 대한 페이징 처리  -->
<c:if test="${paging.page <=1}">[이전] </c:if>
<c:if test="${paging.page >1}">
<a href="pagingList?page=${paging.page-1}&limite=${paging.limit}">[이전]</a>
</c:if>

<!-- 페이지 번호에 대한 페이징 처리  -->
<c:forEach var="i" begin="${paging.startPage}" end="${paging.endPage}"
step="1">
<c:choose>



<c:when test="${paging.page eq i}"> [${i}] </c:when>

<c:otherwise>
<a href="pagingList?page=${i}"> ${i}</a>
</c:otherwise>
</c:choose>

</c:forEach>


<!-- 다음 페이지로 에 대한 페이징 처리  -->
<c:if test="${paging.page >= paging.maxPage}">[다음] </c:if>
<c:if test="${paging.page <paging.maxPage}">
<a href="pagingList?page=${paging.page+1}&limite=${paging.limit}"> [다음]</a>
</c:if>


<br />
<input type="button" value="뒤로가기" onclick="history.back(-1);">

</body>
</html>

------------------------------------

mapper의 sql문


<update id="modify" parameterType ="board">
UPDATE BOARDDTO SET BWRITER =#{bWriter}, BPASSWORD = #{bPassword}, BTITLE = #{bTitle}, BCONTENT = #{bContent}, BFILENAME = #{bFileName} WHERE BNUM = #{bNum}
</update>
<delete id="delete" parameterType = "int">
DELETE FROM BOARDDTO WHERE BNUM = #{bNum}
</delete>

<select id ="count" resultType = "int">
SELECT COUNT(*) FROM BOARDDTO
</select>

<select id ="plist" parameterType ="paging" resultType = "board">
SELECT * FROM BOARDLIST WHERE RN BETWEEN #{startRow} AND #{endRow}
</select>

1번이 지금 쓰는 방식이고 

2번은 옛날 방식이다.

'하루정리' 카테고리의 다른 글

2022.04.25 회원가입&게시판  (0) 2022.04.25
자바스프링 설정, 톰캣 설치 및 설정  (0) 2022.04.25
2020.04.21 하루 정리 프로젝트 기본  (0) 2022.04.21
2022.04.20 정리  (0) 2022.04.20
2022.04.18 하루 정리  (0) 2022.04.18