在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来存储。
prefix:给trim标签内的sql语句加上前缀
suffix:给trim标签内的sql语句加上后缀
suffixOverrides:去除多余的后缀,如:suffixOverrides=",",则表示去除trim标签内sql语句多余的逗号后缀
prefixOverrides:去除多余的前缀
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="guid != null">
guid,
</if>
<if test="companyGuid != null">
company_guid,
</if>
</trim>
打印mysql日志(yml格式)
logging:
level:
com.payermax.omc.channel.exchange.dao.mapper: trace
如果要打印Mysql的日志(application.properties文件):mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl