게시글에 파일 첨부기능을 만들던 도중 EmptyResultDataAccessException이 발생하였다.
DAO에서 파일 첨부 정보가 있는 글만 정상적으로 return되고 있었던 것이 문제가 되어
파일 첨부 정보가 없는 글은 EmptyResultDataAccessException가 발생하는 것이었다.
따라서 DAO에 try-catch 구문을 추가해서 EmptyResultDataAccessException에러가 발생했을 때
NULL값을 반환하도록 수정해주니 파일 첨부 정보가 없는 글 또한 정상적으로 조회가 가능하게 되었다.
기존 코드
public BoardAttachDto getAttachInfo(int boardSeq,int boardTypeSeq) {
String sql = "SELECT * FROM board_attach ba "
+ "WHERE ba.board_seq = ? "
+ " AND ba.board_type_seq = ?";
Object[] args = {boardSeq,boardTypeSeq};
return queryForObject(sql, new BoardAttachRowMapper(), args);
}
수정된 코드
public BoardAttachDto getAttachInfo(int boardSeq,int boardTypeSeq) {
String sql = "SELECT * FROM board_attach ba "
+ "WHERE ba.board_seq = ? "
+ " AND ba.board_type_seq = ?";
Object[] args = {boardSeq,boardTypeSeq};
try {
return queryForObject(sql, new BoardAttachRowMapper(), args);
} catch (EmptyResultDataAccessException e) {
// 파일 첨부 정보가 없는 경우에도 null을 반환하도록 수정
return null;
}
}
| DateFormat 작성 시 주의할 점 (1) | 2024.05.14 |
|---|---|
| NumberFormatException이 왜 발생했는가? (0) | 2024.05.13 |
| Dao새로 만들었을때 주의할점 (0) | 2024.05.11 |
| 게시글 작성 후 새로고침하면 계속 같은 게시글이 생성되는 에러 (0) | 2024.05.10 |
| 로그에서 발생한 "/10/forum/notice/thumb-up.do" 경로에 대한 404 오류 (0) | 2024.05.10 |