본문 바로가기
Spring

[spring] Mapper method 'com.kjh.sanction.mapper.SanctionMapper.tmprAt attempted to return null from a method with a primitive return type (int).]을(를) 발생시켰습니다. 오류 해결하기

by happenstance 2021. 12. 22.

컨트롤러에서 데이터를 조회하는 쿼리를 실행하니 아래와 같은 에러가 발생했다.

org.apache.ibatis.binding.BindingException: 
Mapper method 'com.kjh.sanction.mapper.SanctionMapper.tmprAt 
attempted to return null from a method with a primitive return type (int).

 

내가 반환받을 타입은 int인데 조회한 데이터는 int가 아니기 때문에 조회를 하지 못하고 null을 반환한 것이다.

내가 작성한 쿼리문이다.

	<select id="tmprAt" parameterType="int" resultType="int">
		SELECT 1 
		FROM ELCTRNSANCTN
		WHERE TMPR_AT = 'Y'
			AND ELCTRN_SANCTN_SN = #{elctrnSanctnSn}
	</select>

위 코드를 보면 resultType이 int인데, int 타입으로는 null을 받을 수 없기 때문에 오류가 발생한 것이다.

 

따라서 resultType을 수정해주었다.