如何将条件放入myBatis datamapper.xml

问题描述 投票:2回答:1

这是我想要的

<update id='stoIncrement' parameterType='java.util.Map'>
update DB set 
<if test="#{is_increase} == 1">
count=(select max(count) from DB) +1 
 </if>
<if test="#{is_increase} == 0">
count=(select max(count) from DB) -1 
 </if>
where store=#{store}
</update>

这里is_increase是参数映射的键,而不是表的实体。

但是以上方法似乎无效。有人可以在这方面提供帮助。

谢谢

java sql mybatis ibatis
1个回答
2
投票

使用这样的设置:

<update id='stoIncrement' parameterType='java.util.Map'>
    update DB
    <set>
        <if test="is_increase !=null and  is_increase == 1">
            count=(select max(count) from DB) +1 ,
        </if>
        <if test="is_increase !=null and  is_increase == 0">
            count=(select max(count) from DB) -1 ,
        </if>
    </set>
    where store=#{store}
</update>
© www.soinside.com 2019 - 2024. All rights reserved.