我想知道像下面这样的if语句的用法
<update id="update"
parameterType="com.MyClass">
UPDATE
Board SET Status = 1
<where>
<if test="A != null and A.length() > 0">AND A = ${A}</if>
</where>
</update>当A!=null且A.length() >0时,此语句有效。
但如果为A==null,则更新整个行集1会导致没有where条件。
如果有合适的条件,有没有办法更新,否则跳过或忽略?
谢谢
发布于 2018-01-09 16:05:29
<update id="update"
parameterType="com.MyClass">
UPDATE
Board SET Status = 1
<where>
<choose>
<when test="A != null and A.length() > 0">
AND A = ${A}
</when>
<otherwise>
AND 0 = 1
</otherwise>
</choose>
</where>
</update>当条件0=1时,where将失败,并且不执行任何更新
发布于 2018-06-28 16:18:45
<update id="update" parameterType="com.MyClass"> UPDATE Board SET Status = 1 <where> <![CDATA[<if test="A != null and A.length() > 0">AND A = ${A}</if>]]> </where> </update>
尝试使用CDATA会很好。
https://stackoverflow.com/questions/48162933
复制相似问题