본문 바로가기

IT개발정보/spring and java

스프링 mybatis의 sql문에서 변수명을 sql필드명으로 쓰려면?

스프링 mybatis의 sql문에서 변수명을 sql필드명으로 쓰려면?

mybatis에서 변수에 있는 내용을 쿼리문에 넣을때 #{xxx} 이런식으로 쓰는데

만약 변수값을 sql필드명으로 대체하려면 ${xxx} 이렇게 써야 한다.

#인지 $인지가 중요!

ex) 예를 들어 아래와 같다
<select id=”list” resultType=”BoardVO”>
<![CDATA[
Select idx,uname,title,pwd,click,ref,re_step,re_lvl,reg_ip,reg_date
from tbl_board
where idx<>”
]]>
<if test=”SearchOpt!=null and SearchOpt!=””>
<if test=”SearchVal!=null and SearchVal!=””>
and ${SearchOpt} like CONCAT(‘%’,#{SearchVal},’%’)
</if>
</if>
<![CDATA[
order by ref desc, re_step, re_lvl
limit #{intPage},#{intPageSize}
]]>
</select>