MyBatis Mapper 常用功能配置

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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值