在mapper文件中书写判断参数是否等于某个值
<!-- 正确的,稳定,推荐使用 -->
<if test="newsImage != null and newsImage == '1'.toString()">
<![CDATA[ and len(newsImage) > 0 ]]>
</if>
<!-- 正确的,稳定,推荐使用 -->
<if test="newsImage != null and newsImage == 'y'.toString()">
<![CDATA[ and len(newsImage) > 0 ]]>
</if>
判断List不为空且遍历list
<if test="bookIds!=null and bookIds.size()>0">
and book_id in
<foreach item="item" index="index" collection="bookIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
将查询出了的结果转成其他值
将结果转成其他值
CASE
WHEN s.s_sex = '1' THEN '男'
WHEN s.s_sex = '2' THEN '女'
ELSE '其他'
END as sex,
讲表中的s_sex如果为1转成男,2转成女,否者转成其他,并且把s_sex字段转成sex
通过查询出来的结果,用来统计单项值出现的次数
count( CASE WHEN tqcr.sender =1 THEN tqcr.sender ELSE NULL END ) customerMsgCount,
这个原理和上面的很类似,讲查询出来的结果判断是否等于某个值,如果成立,保持原样,否者计为空,然后再通过count来统计非空的值出现的次数,再把结果用字段customerMsgCount来存储。