myBatis에서 selectone으로 검색시 결과값이 없는데 int절에 넣고 싶을때가 있을것이다.
int절에 넣을때 nullpointerException 오류가 발생하게 된다.
//service
int testCnt = testDAO.selectTestCnt(testVO);
//mapper
//dao
public int selectTestCnt(TestVO testVO) {
return ((Integer) sqlSession.selectOne(NAMESPACE + "selectTestCnt", testVO)).intValue();
}
service 단에서 nullpointerException 오류 발생
이럴때는..........이렇게 해보세요~~!!!
//int testCnt = testDAO.selectTestCnt(testVO);
//dao
public int selectTestCnt(TestVO testVO) {
return sqlSession.selectOne(NAMESPACE + "selectTestCnt", testVO;
}
//service
Integer testCnt = testDAO.selectTestCnt(testVO);
testCnt = testCnt == null ? 0 : testCnt;
'개발 > JAVA' 카테고리의 다른 글
| byte Array to (0) | 2023.04.20 |
|---|---|
| [Java] Byte Reverse (0) | 2023.04.20 |
| Spring VO 객제 복사 하기 (0) | 2017.08.04 |
| java 인코딩 깨질때 [한글 인코딩 오류] 체크 (0) | 2017.07.21 |
| Java split 사용법 (0) | 2017.04.05 |