Spring/DB_MyBatis
[MyBatis] parameter type string if문 사용법
snow_hong
2024. 1. 15. 17:05
MyBatis문에서 parameter type string시에 해당 if문을 잘못사용하면 에러가 발생한다.
[오류난 코드]
<select id="test" parameterType="String" resultType="egovMap">
SELECT *
FROM 테이블명
<if test='id eq "test" '>
//test아이디일 경우
WHERE 컬럼명 = #{id}
</if>
</select>
org.apache.ibatis.reflection.ReflectionException:There is no getter for property named 'id' in 'class java.lang.String'
해당 String getter값이 없다고 한다.
mybatis에서 Vo를 사용한게 아니라면 value 값으로 확인해야한다.
하지만 <if test ='value eq "test">로 표현하면 오류는 발생하지 않지만, if문이 제대로 실행은 안된다.
[ 해결방법 ] : _parameter 로 파라미터를 지칭
<select id="test" parameterType="String" resultType="egovMap">
SELECT *
FROM 테이블명
<if test='_parameter != null and _parameter != "" '>
WHERE 컬럼명 = #{id}
</if>
</select>
_parameter로 적용하면 잘 된다.
원인 : _parameter is undocumented. MyBatis is a nice framework but, sadly, lacks on the documentation part 설명처럼 문서화가 부족한 부분이 있어 쉽게 해법을 찾지 못하고 헤멧던 것!
728x90