ssm动态SQL<if>标签使用问题注意

mac2022-06-30  34

自己在使用动态sql的时候也是遇到一个问题,这里记录一下:

<select id="getOrdersForPrepare1" resultType="order.View.OrderView"> select * from OrderView <where> <if test="type == 3"> additional = #{additional} </if> and type = #{type} and eatDate between #{date1} and #{date2} and placeID in <foreach collection="ids" item="id" index="index" open="(" close=")" separator=","> #{id} </foreach> </where> </select>

这里的if标签后面接上了一些不需要进行判断的条件,本来前面我没有加and,后面发现当if标签里面的结果符合type ==3时,这时就会报错,后面加上and就没问题了。

最新回复(0)