본문 바로가기
Spring

[Spring] Mybatis 동적 쿼리 사용 중 Parameter를 String으로 넘길때 발생하는 문제

by Real Iron 2019. 3. 5.

mybatis 로그인 xml에서 파라미터가 string으로 넘어오는 where절만 mybatis문법으로 사용하면  

 

HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: 
nested exception is org.apache.ibatis.reflection.ReflectionException: 
There is no getter for property named 'mbrId' in 'class java.lang.String'

위와 같이 에러가 났다.

 

string은 getter방식이 아니라 에러가 난다고 한다.

그래서 3번과 같이 value로 넣어주니 알아서 파라미터 값이 변경되어 들어오는지 에러없이 잘된다.

 

 


그렇지만 다른방법으로 파라미터가 한개지만 map에 담아서 보내주니 where절로 파라미터를 받을 수 있게 되었다.

ex)

<select id="getMemberInfo" parameterType="map" resultType="MemberVO"> 

   select * from MEMBER 

    <where> 

   <if test="mbrId != null">

        mbr_id = #{mbrId}

   </if> 

    </where> 

    </select>


name을 가져오는 방식이 parameterType 안에 들어있는 클래스에서 getter 메소드로 name을 받아오기 때문이다.

즉, 에러 그대로 String 객체에 name을 뱉어주는 getter 메소드가 없기 때문이다. 

- Primitive Type의 값도 문제 없이 된다. (int, long 같은 기본 데이터 타입)

- Map 사용 가능함

String 하나때문에 Map으로 감싸서 보냈다.