728x90
1. JSP 글 수정 페이지
글보기의 방법처럼 글 정보를 불러와 다시 작성하여 수정할 수 있도록
<Input>, <textarea> 태그에 값으로 지정해 줍니다
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<form method="post" action="updateAct?bbsID=${boardDTO.bbsID}">
<table class="table table-striped"
style="text-align: center; border: 1px solid #dddddd">
<thead>
<tr>
<th colspan="2"
style="background-color: #eeeeee; text-align: center;">게시판
수정 양식</th>
</thead>
<tbody>
<tr>
<td><input type="text" class="form-control"
placeholder="글 제목" name="bbsTitle" maxlength="50" value="${boardDTO.bbsTitle}" ></td>
</tr>
<tr>
<td><textarea class="form-control" placeholder="글 내용"
name="bbsContent" maxlength="2048" style="height: 350px;">${boardDTO.bbsContent}</textarea></td>
</tr>
</tbody>
</table>
<input type="submit" class="btn btn-primary pull-right" value="글 수정">
</form>
|
cs |
2. 글 수정 Controller
1
2
3
4
5
6
7
8
9
|
//게시글 수정
@RequestMapping(value = "/updateAct", method = RequestMethod.POST)
public String updateAct(HttpServletRequest request, HttpServletResponse response,
BoardDTO boardDTO) {
boardSvc.updateBoard(boardDTO);
return "redirect:/board";
}
|
cs |
3. 글 수정 Service
1
2
3
4
|
//게시글 수정
public void updateBoard(BoardDTO boardDTO) {
session.update("updateBoard", boardDTO);
}
|
cs |
4. 글 수정 Update 쿼리
1
2
3
4
5
|
<!-- 게시글 수정 -->
<update id="updateBoard" parameterType="com.board.BoardDTO">
UPDATE bbs.bbs SET bbsTitle = #{bbsTitle}, bbsContent = #{bbsContent}
WHERE bbsAvailable = 1 AND bbsID = #{bbsID}
</update>
|
cs |
5. 글 삭제 Controller
1
2
3
4
5
6
7
8
9
10
11
12
13
|
//게시글 삭제
@RequestMapping(value = "/deleteAct", method = RequestMethod.GET)
public String deleteAct(HttpServletRequest request, HttpServletResponse response,
@RequestParam int bbsID) {
String userID = (String) request.getSession().getAttribute("userID");
Map<String, Object> map = new HashMap<String, Object>();
map.put("bbsID", bbsID);
map.put("userID", userID);
boardSvc.deleteBoard(map);
return "redirect:/board";
}
|
cs |
3. 글 삭제 Service
1
2
3
4
|
//게시글 삭제
public void deleteBoard(Map<String, Object> map) {
session.update("deleteBoard", map);
}
|
cs |
4. 글 삭제 Update 쿼리
데이터 삭제 쿼리는 Delete문이지만 사용유무로 글의 사용 여부를 확인하기 때문에
Update문을 사용한다
1
2
3
4
5
|
<!-- 게시글 삭제 -->
<update id="deleteBoard" parameterType="java.util.Map">
UPDATE bbs.bbs SET bbsAvailable = 0
WHERE bbsID =#{bbsID} AND userID = #{userID}
</update>
|
cs |
'게시판 만들기 > JSP ➜ Spring' 카테고리의 다른 글
[Spring] 파일 업로드/다운로드 (0) | 2023.02.13 |
---|---|
[Spring]2. 게시판 구현 CRUD - 글 보기 (0) | 2023.02.10 |
[Spring]1. 게시판 구현 CRUD - 글쓰기 (0) | 2023.02.09 |
[Spring] 게시판 구현 페이징 처리 (0) | 2023.02.08 |
[Spring] 메인 페이지/내비게이션 <jsp:include> (0) | 2023.02.07 |