<when test="rateModel.searchDayFlag != null and rateModel.searchDayFlag=='1'">
and t.calc_time = #{rateModel.calcTime}
</when>
<otherwise>
and t.calc_time = #{rateModel.yesterday}
</otherwise>
</choose>
今天遇到一個問題,就是sql進不了when標籤裏面,我糾結了半天,最後才發現原因:
雙引號和單引號是互用的 但是字符串判斷那裏要用雙引號,改成下面這樣就好了
<choose>
<when test='rateModel.searchDayFlag != null and rateModel.searchDayFlag=="1"'>
and t.calc_time = #{rateModel.calcTime}
</when>
<otherwise>
and t.calc_time = #{rateModel.yesterday}
</otherwise>
</choose>
而且,我前面寫的是=‘1’,這也是 不對的,字符串要==或者用equals() 就搞定了,以後注意。