http://marobiana.tistory.com/m/14


1. 맨 끝에 있는 콤마(,)를 제거하는 경우

<update id="updateAuthorIfNecessary" parameterType="domain.blog.Author">
UPDATE AUTHOR
 <trim prefix="SET" suffixOverrides=",">
  <if test="username != null">username=#{username},</if>
  <if test="password != null">password=#{password},</if>
  <if test="email != null">email=#{email},</if>
  <if test="bio != null">bio=#{bio},</if>
 </trim>
WHERE id=#{id}
</update>
맨앞에 SET을 붙이고 if안에 무엇이 들어가도 맨 끝에 있는 콤마를 지우겠다는 것이다.


2. 맨 앞에 있는 연산자를(AND 또는 OR) 제거하는 경우

<select id="selectInfo" parameterType="domain.blog.Author" resultType="authorResultMap">
  SELECT * FROM AUTHOR
  <trim prefix="WHERE" prefixOverrides="AND |OR">
  <if test="username != null>AND username=#{username}</if>
  <if test="password != null>OR password=#{password}</if>
  <if test="email != null>AND email=#{email}</if>
 </trim>
</select>
요번에는 앞에 들어가는 AND 또는 OR을 제거하겠다는 것이다.

'mybatis' 카테고리의 다른 글

null, empty 문자 비교, boolean 비교  (0) 2019.07.26
myBatis java configuration  (0) 2018.12.20
mybatis 내장 cache  (0) 2018.11.15
myBatis empty()함수 사용하기  (0) 2015.12.15
mybatis 사이트  (0) 2015.03.11
Posted by 張's blog
,