[쏘쓰] mybatis error

wstudee·2022년 11월 2일
0

쏘쓰

목록 보기
2/2

String 파라미터 한개일 때

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userId' in 'class java.lang.String'

에러발생 쿼리

<update id="쿼리아이디" parameterType="java.lang.String">
	UPDATE ~~~
	   SET ~~~
	 WHERE 1=1 
	   <if test="@org.apache.commons.lang.StringUtils@isNotEmpty(usid)">	
	   and usid = #{usid}
	   </if>
</update>

오류 발생원인

  • 특정 조건들이나 상황에 따라 변경되는 동적쿼리에서
    parameterType = "java.lang.String"으로 하고
    <if test="@org.apache.commons.lang.StringUtils@isNotEmpty(usid)"> 방식으로 null 체크

https://bcdragonfly.tistory.com/10
동적쿼리의 if문은 파라미터타입클래스(String)의 getter를 호출하는 방식
String 내부에는 getter 개념이 정의되어 있지 않아서 발생

작동하는 쿼리

<update id="쿼리아이디" parameterType="java.lang.String">
	UPDATE ~~~
	   SET ~~~
	 WHERE 1=1 
	   <if test="value != null and value != ''">
	   and usid = #{value}
	   </if>
</update>

0개의 댓글