Posted
Filed under JSP, JAVA

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>
2016/12/01 15:08 2016/12/01 15:08