게시판 유효성 검사
@PostMapping("/modify_pro")
public String modify_pro(@Valid @ModelAttribute("modifyContentBean") ContentBean modifyContentBean, BindingResult result) {
if(result.hasErrors()) {
return "board/modify";
}
return "board/modify_success";
}
@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);
//글 수정
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);
}
@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";
}
<script>
alert("수정 되었습니다.")
location.href="${root}board/read?board_info_idx=${modifyContentBean.content_board_idx}&content_idx=${modifyContentBean.content_idx}"
</script>
DB와 화면에 출력이 잘 되는걸 볼 수 있다.