@Insert("insert into content_table(content_subject, content_text, " +
"content_file, content_writer_idx, content_board_idx, content_date) " +
"values (#{content_subject}, #{content_text}, #{content_file, jdbcType=VARCHAR}, " +
"#{content_writer_idx}, #{content_board_idx}, now())")
void addContentInfo(ContentBean writeContentBean);
public void addContentInfo(ContentBean writeContentBean) {
MultipartFile upload_file = writeContentBean.getUpload_file();
if(upload_file.getSize() > 0 ) {
//위의 메서드로 파일을 저장하고 그 이름을 가져옴
String file_name = saveUploadFile(upload_file);
//파일의 이름을 저장한다
writeContentBean.setContent_file(file_name);
}
//글쓴이는 현재 로그인 된 유저
writeContentBean.setContent_writer_idx(loginUserBean.getUser_idx());
boardMapper.addContentInfo(writeContentBean);
}
@PostMapping("/write_pro")
public String write_pro(@Valid @ModelAttribute("writeContentBean") ContentBean writeContentBean,
BindingResult result) {
if (result.hasErrors()) {
return "board/write";
}
//db에 저장
boardService.addContentInfo(writeContentBean);
return "board/write_success";
}
DB에 잘 들어간걸 확인할 수 있다.