boardView.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:import url="/WEB-INF/views/common/header.jsp"/>
<div class="container">
<h2>자유게시판</h2>
<table class="table" id="boardView" style="width:100%;">
<tr class="table-active">
<th colspan="1">제목</th>
<th colspan="3">${board.boardTitle }</th>
</tr>
<tr>
<th>작성자</th>
<td>${board.boardWriter }</td>
<th>작성일</th>
<td>${board.regDate }</td>
</tr>
<tr>
<th>첨부파일</th>
<c:choose>
<c:when test="${not empty board.fileName }">
<td>
<img src="/resources/img/file.png" width="16px">
<a href="/fileDown.do?filepath=${board.filePath }&filename=${board.fileName }">${board.fileName }</a>
</td>
</c:when>
<c:otherwise>
<td>첨부파일 없음</td>
</c:otherwise>
</c:choose>
<th>조회수</th>
<td>${board.readCount }</td>
</tr>
<tr>
<th>내용</th>
<td colspan="3" style="height:300px;">${board.boardContent }</td>
</tr>
<tr>
<th colspan="4" style="text-align:center;">
<a href="javascript:history.back();" class="btn btn-primary">이전화면</a>
<c:if test="${sessionScope.m.memberId eq board.boardWriter}">
<a href='/boardUpdateFrm.do?boardNo=${board.boardNo }' class="btn btn-primary">수정하기</a>
<a href='/boardDelete.do?boardNo=${board.boardNo }' class="btn btn-primary">삭제하기</a>
</c:if>
</th>
</tr>
</table>
</div>
<c:import url="/WEB-INF/views/common/footer.jsp"/>
</body>
</html>
#이전화면
자바스크립트에서 history 객체는 브라우저의 history정보를 저장하는 객체이다.
history.back(); 은 현재페이지에서 바로 이전의 페이지로 이동시켜주는 메서드이다.
<a href="javascript:history.back();" class="btn btn-primary">이전화면</a> 를 작성해주면 이전페이지로 돌아가는 것을 볼 수 있다.
#수정하기
boardController.java
//수정
@RequestMapping(value="/boardUpdate.do")
public String boardUpdate(Board b, Model model) {
int result = service.boardUpdate(b);
if(result > 0) {
model.addAttribute("msg","게시물 수정 완료~!");
}else {
model.addAttribute("msg","게시물 수정 실패ㅠㅠ");
}
model.addAttribute("loc","/boardView.do?boardNo="+b.getBoardNo());
return "common/msg";
}
boardService.java
@Transactional
public int boardUpdate(Board b) {
return dao.boardUpdate(b);
}
boardDao.java
public int boardUpdate(Board b) {
return session.update("board.boardUpdate",b);
}
boardSQL.xml
<update id="boardUpdate" parameterType="b">
update board set board_title=#{boardTitle}, board_content=#{boardContent} where board_no=#{boardNo}
</update>
#삭제하기
boardController.java
//삭제
@RequestMapping(value="/boardDelete.do")
public String boardDelete(int boardNo, Model model) {
int result = service.boardDelete(boardNo);
if(result > 0) {
model.addAttribute("msg","게시물 삭제 성공~!");
}else {
model.addAttribute("msg","게시물 삭제 실패ㅠㅠ");
}
model.addAttribute("loc","/board.do?reqPage=1");
return "common/msg";
}
boardService.java
@Transactional
public int boardDelete(int boardNo) {
return dao.boardDelete(boardNo);
}
boardDao.java
public int boardDelete(int boardNo) {
return session.delete("board.boardDelete",boardNo);
}
boardSQL.xml
<delete id="boardDelete" parameterType="int">
delete from board where board_no=#{boardNo}
</delete>
반응형
'spring > 게시판 만들기' 카테고리의 다른 글
[spring] 게시판 주제별 검색기능 구현 (0) | 2022.03.01 |
---|---|
[spring] 스프링 게시판 checkbox 체크되었을 때 1, 안되었을 때 0 표현 (0) | 2022.02.20 |
[spring] 스프링게시판 페이징(paging) 처리 (0) | 2022.02.18 |
[spring/mybatis] 게시판 조회수 (0) | 2022.02.16 |
[spring/mybatis] 게시판 리스트 출력 (0) | 2022.02.15 |