글 수정하기2

JEONG SUJIN·2022년 12월 30일
0

BoardController.java

게시판 유효성 검사

@PostMapping("/modify_pro")
	public  String modify_pro(@Valid @ModelAttribute("modifyContentBean") ContentBean modifyContentBean, BindingResult result) {
		if(result.hasErrors()) {
			return "board/modify";
		}
		return "board/modify_success";
	}

BoardMapper.java

@Update("update content_table " + 
			"set content_subject = #{content_subject}, content_text = #{content_text}, " + 
			"content_file = #{content_file, jdbcType=VARCHAR} " +
			"where content_idx = #{content_idx}")
	void modifyContentInfo(ContentBean modifyContentBean);

BoardService.java

//글 수정
	public void modifyContentInfo(ContentBean modifyContentBean) {
		MultipartFile upload_file = modifyContentBean.getUpload_file();
		
		if(upload_file.getSize() > 0) {
			String file_name = saveUploadFile(upload_file);
			modifyContentBean.setContent_file(file_name);
            }
		
		boardMapper.modifyContentInfo(modifyContentBean);
	}
    

BoardController.java

@PostMapping("/modify_pro")
	public  String modify_pro(@Valid @ModelAttribute("modifyContentBean") ContentBean modifyContentBean, BindingResult result) {
		
		if(result.hasErrors()) {
			return "board/modify";
		}
		//db에 업데이트
		boardService.modifyContentInfo(modifyContentBean);
		return "board/modify_success";
	}

modify_success.jsp

<script>
alert("수정 되었습니다.")
location.href="${root}board/read?board_info_idx=${modifyContentBean.content_board_idx}&content_idx=${modifyContentBean.content_idx}"
</script>

DB와 화면에 출력이 잘 되는걸 볼 수 있다.

profile
기록하기

0개의 댓글