Post

[MyBatis] java.lang.NumberFormatException Error 해결



MyBatis logo




java.lang.NumberFormatException : For input string: “Y”

문자열 비교 구문에서 뜬금없이 NumberFormatException이 발생했다.

문제가 된 구문

1
2
3
     <if test="value == 'Y'">
          AND STATUS = 'active'
     </if>



원인

OGNL(Object Graph Navigation Language) 인터프리터에서 ‘Y’같이 한 글자를 홑따옴표(‘‘)에 담으면 char형으로 인식해 나는 오류였다.



해결

1
2
3
     <if test='value == "Y"'>
          AND STATUS = 'active'
     </if>

쌍따옴표를 홑따옴표로 바꾸니 해결됐다.



Mybatis에서 동적쿼리를 사용하는 경우 홑따옴표(‘‘)를 사용해 자잘한 오류를 예방하자.


This post is licensed under CC BY 4.0 by the author.