/**
* 게시물 수정화면 연결
* @param mv
* @param boardNo
* @return
*/
@RequestMapping(value="/board/modifyView.kh", method = RequestMethod.GET)
public ModelAndView boardModifyView(ModelAndView mv,
@RequestParam("boardNo") Integer boardNo) {
try {
Board board = bService.printOneVyNo(boardNo);
if(board!=null){
mv.addObject("board",board);
mv.setViewName("board/modifyForm");
}
}
catch (Exception e) {
e.printStackTrace();
mv.addObject("mgs",e.getMessage());
mv.setViewName("/common/errorPage");
}
return mv;
}
/board/modifyView.kh
를 겟방식으로 접속하면 해당 폼이 나오도록 만들었다.
bService.printOneVyNo(boardNo)
<h1 align="center">${board.boardNo }번 게시물 수정하기</h1>
<br>
<br>
<!-- enctype을 이용해 파일을 전송한다 오타조심!!!!-->
<form action="/board/modify.kh" method="post" enctype="multipart/form-data">
<input type="hidden" name="boardNo" value="${board.boardNo }" readonly>
<table align="center" border="1">
<tr>
<td>제목</td>
<td><input type="text" name="boardTitle" value="${board.boardTitle }"></td>
</tr>
<tr>
<td>작성자</td>
<td><input type="text" name="boardWirter" value="${board.boardWirter }" readonly="readonly"></td>
</tr>
<tr>
<td>내용</td>
<td><textarea id="summernote" name="boardContents"
style="resize: none; width: 500px; height: 100%;"> ${board.boardContents }</textarea></td>
</tr>
<tr>
<td>첨부파일</td>
<td><input type="file" name="uploadFile">
<a href="#"> ${board.boardFile }</a>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="등록"> <input
type="reset" value="취소">
<a href="#">목록으로</a>
<a href="#">이전페이지로</a>
</td>
</tr>
</table>
</form>
<script>
$('#summernote').summernote({
height : 300, // set editor height
minHeight : null, // set minimum height of editor
maxHeight : null, // set maximum height of editor
focus : true, // set focus to editable area after initializing summernote
});
$('[aria-label="Picture"]').css('display','none');
</script>
/**
*게시물 수정코드*/
@RequestMapping (value="/board/modify.kh", method = RequestMethod.POST)
public ModelAndView modifyBoard(ModelAndView mv,
@ModelAttribute Board board) {
try {
int result = bService.modifyBoardOneByNo(board);
if(result>0) {System.out.println("성공");}else { System.out.println("실패");}
mv.setViewName("redirect:/board/detail.kh?boardNo="+board.getBoardNo());
}catch (Exception e) {
e.printStackTrace();
mv.addObject("mgs",e.getMessage());
mv.setViewName("/common/errorPage");
}
return mv;
}
@ModelAttribute Board board
를 통해 board로 저장되었다,@Override
public int modifyBoardOneByNo(Board board) {
int result = bStore.updateBoardOneByNo(board, session);
return result;
}
@Override
public int updateBoardOneByNo(Board board, SqlSessionTemplate session) {
int result = session.update("BoardMapper.modifyBoard",board);
return result;
}
<update id="modifyBoard">
update board_tbl set board_title = #{boardTitle}, BOARD_CONTENTS = #{boardContents} where BOARD_NO = #{boardNo}
</update>
/**
*게시물 수정코드*/
@RequestMapping (value="/board/modify.kh", method = RequestMethod.POST)
public ModelAndView modifyBoard(ModelAndView mv,
@ModelAttribute Board board) {
try {
int result = bService.modifyBoardOneByNo(board);
mv.setViewName("redirect:/board/detail.kh?boardNo="+board.getBoardNo());
}catch (Exception e) {
e.printStackTrace();
mv.addObject("mgs",e.getMessage());
mv.setViewName("/common/errorPage");
}
return mv;
}