Notice
Link
- Today
- Total
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 말줌임 CSS
- Back 키 클릭 감지
- reactnative
- 스크롤적용
- 시간대 테이블생성
- group by
- 터치좌표 view
- 시간대별 통계
- 피쉬랜드
- view 획득
- sql exception
- springboot
- CSS
- c언어
- 파티션 빠른 삭제
- rn
- SQL
- MySQL
- kill -9
- vc++
- pid 찾아 kill
- MariaDB
- Activity 전체화면
- MFC
- 코드로 서버 재실행
- mybatis exception
- 가변영역 스크롤
- springboot 재가동
- ffmpeg
- CentOS
Archives
개발은 하는건가..
[mybatis] Sql Exception 처리 본문
반응형
Repository 에 다음과 같이 DataAccessException 을 throws 해준다.
@Repository
@Mapper
public interface UserRepository {
int insertUser(UserInfoDTO uid) throws DataAccessException;
}
아래와 같이 서비스에서 Repository 함수를 호출하면서 Exception 을 catch 하여 처리해준다.
@Service
@RequiredArgsConstructor
public class UserService {
private final UserRepository _UserRepo;
public int addUser(UserInfoDTO user) {
int res = 0;
try {
user.setPwd(CryptoUtils.getSHA256(user.getPwd()));
res = _AdminRepo.insertUser(user);
} catch (DataAccessException e) {
if (e instanceof DuplicateKeyException) {
// 중복 키
log.error("DuplicateKeyException");
res = 1;
}
else if (e instanceof DataIntegrityViolationException) {
// 허용하지 않은 필드 타입 매칭 또는 Null 허용 안함 필드 null 매칭
log.error("DataIntegrityViolationException");
res = 2;
}
else {
log.error(e.getCause().getMessage());
res = 3;
}
}
return res;
}
'SpringBoot , Thymeleaf' 카테고리의 다른 글
[springboot] RestTemplate 를 이용한 간단하게 http 요청 (1) | 2024.01.03 |
---|---|
[Springboot] 서버 재가동 RestAPI 코드 작성 (0) | 2023.08.25 |
[lo4j2] 로그 파일로 생성되게 하기 (2) | 2023.06.09 |
mybatis DTO 클래스 aliasesPackage 지정 (0) | 2023.05.25 |
[springboot] application.properties 프로파일별로 따로두기 (0) | 2023.02.20 |
Comments