MyBatis中如何计算加减乘除:

先来看一下mysql中的写法:

update table set
 bean = (case when FLOOR(((bean / 400) * 675)) > 5000 then 5000 else FLOOR(((bean / 400) * 675)) end)
        where DATE_TIME = '2021-02-05'

这里的FLOOR是舍小数位,向下取整。

再来看一下MyBatis的写法:

<update id="updateDetailAwardBean" parameterType="java.util.Map">
        update table set
            bean = (case when FLOOR(((bean / ${param.guessBeanCount}) * ${param.sumPrizePool})) > 5000 then 5000 else FLOOR(((bean / ${param.guessBeanCount}) * ${param.sumPrizePool})) end)
        where DATE_TIME = #{param.currentDate,jdbcType=VARCHAR}
    </update>

这里需要注意的是传入参数的#和$的用法。
尝试过用#传入参数指定jdbcType=INTEGER,不好使,只能写$

或者用<![CDATA[]]>将代码写入中括号里面。这样就会被认为是纯文本。

以上就是MyBatis中计算数值的方式,感谢各位观看,如果有不对的地方还请各位大佬指教。

更多推荐

MyBatis中如何计算数值