平时都是复制粘贴或者插件生成的动态sql,今天要写一个根据条件判断的sql,居然一直报错。
百度一通,才知道原来这里面这么多坑,记录下我目前遇到的一个,后续遇到再在这里添加吧
<select id="getPointCountInCircle" parameterType="map" resultType="int">
select ifnull(count(id),0) from r_point
<where>
user_id = #{user_id} and reason = #{reason}
<if test="circle == '0'.toString()">
</if>
<if test="circle == '1'.toString()">
and date(creat_time) =current_date
</if>
<if test="circle == '2'.toString()">
and YEARWEEK(date_format(creat_time,'%Y-%m-%d'),1) = YEARWEEK(now(),1)
</if>
</where>
</select>
之前的错误格式我也不写了,反正if test判断字符串还只能这么写