MyBatis Mapper 常用功能配置
熊孩纸
阅读:769
2021-03-31 16:51:06
评论:0
1、MyBatis Mapper文件中的if 标签判断特定字符串是否相等:
<!-- 仅仅查询普通用户 -->
<if test="isCommon != null and isCommon !=''">
<if test="isCommon == '1'.toString()">
AND AUTH_USER.USER_CATEGORY = 'COMMON_USER'
</if>
</if>
2、MyBatis Mapper 文件中的delete 标签批量删除用户集合
<delete id="deleteBySids" parameterType="java.util.List">
delete from data_category where id_ in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</delete>
3、MyBatis Mapper文件中choose when otherise 标签使用= if else 标签
<!--if else 标签判断 -->
<choose>
<when test="order != null and order != '' and order == '1'.toString()">
order by arch_info.created_dt desc
</when>
<otherwise>
order by arch_info.created_dt asc
</otherwise>
</choose>
4、MyBatis Mapper 文件中if 标签判断整数类型是否相等
<choose>
<when test="type!= null and type== 2">
and type = 2
</when>
<otherwise>
and type = 1
</otherwise>
</choose>
注意:mybatis默认将integer=0的参数等于‘’空串 = type ==''
5、MyBatis Mapper 文件中if 标签判断List 集合不能为空
<if test="sids != null and sids.size() > 0">
and sid not in
<foreach collection="sids" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。