SpringBoot 게시판 만들기

스프링부트(SpringBoot) 게시판 만들기8 - 게시글 수정(update), 삭제(delete)

dev109 2017. 8. 20.
반응형

게시글 수정(update) , 삭제(delete)






1.  boardUpdate.jsp 수정


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<%@ 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
 
<h2> 게시글 수정 </h2>
 
<div class="container">
    <form action="/updateProc" method="post">
      <div class="form-group">
        <label for="subject">제목</label>
        <input type="text" class="form-control" id="subject" name="subject" value="${detail.subject}">
      </div>
      <div class="form-group">
        <label for="content">내용</label>
        <textarea class="form-control" id="content" name="content" rows="3">${detail.content}</textarea>
      </div>
      <input type="hidden" name="bno" value="${bno}"/>
      <button type="submit" class="btn btn-primary">수정</button>
    </form>
</div>
 
<%@ include file="bootstrap.jsp" %>
</body>
</html>
cs






2. BoardController.java 에 boardUpdateProc() 수정


1
2
3
4
5
6
7
8
9
10
11
12
@RequestMapping("/updateProc")
    private String boardUpdateProc(HttpServletRequest request) throws Exception{
        
        BoardVO board = new BoardVO();
        board.setSubject(request.getParameter("subject"));
        board.setContent(request.getParameter("content"));
        board.setBno(Integer.parseInt(request.getParameter("bno")));
        
        mBoardService.boardUpdateService(board);
        
        return "redirect:/detail/"+request.getParameter("bno"); 
    }
cs





3. detail.jsp 에 수정, 삭제 버튼 추가

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<%@ 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Detail</title>
</head>
<body>
 
 
<h2> 게시글 상세 </h2>
 
<button class="btn btn-primary" onclick="location.href='/update/${detail.bno}'">수정</button<!-- 추가 -->
<button class="btn btn-danger" onclick="location.href='/delete/${detail.bno}'">삭제</button>  <!-- 추가 -->
 
<div class="container">
    <form action="/insertProc" method="post">
      <div class="form-group">
        <label>제목</label>
        <p>${detail.subject}</p>
      </div>
      <div class="form-group">
        <label>작성자</label>
        <p>${detail.writer}</p>
      </div>
      <div class="form-group">
        <label>작성날짜</label>
        <p>${detail.reg_date}</p>
      </div>
      <div class="form-group">
        <label>내용</label>
        <p>${detail.content}</p>
      </div>
      <button type="submit" class="btn btn-primary">작성</button>
    </form>
</div>
 
 
<%@ include file="bootstrap.jsp" %>
</body>
</html>
cs





4. 프로젝트 재 실행 후 http://localhost:8080/detail/1 접속 후 수정버튼 클릭






5. 수정페이지 확인





6. 삭제버튼 클릭해서 삭제도 확인



게시판 기본적인 기능 구현 끝!!

반응형

댓글

💲 추천 글