MyBatis Mapper 常用功能配置

2023-11-02

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>

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MyBatis Mapper 常用功能配置 的相关文章

  • QGLViewer+VS(MSVC2013)配置

    工具 libQGLViewer 2 7 2 Visual Studio 2013 Uitimate QT5 9 1 MSVC2013 另外在VS中使用QT显示界面需要下载qt vsaddin msvc2013 2 2 0 vsix官网下载
  • STM32的HAL库开发系列 - GPIO中断/外部中断EXTI

    STM32的HAL库开发系列 GPIO中断 外部中断EXTI 中断它可以在GPIO口的电平发生变化时产生中断 从而使得STM32微控制器能够及时响应外部设备的变化 STM32的GPIO中断 外部中断EXTI可以配置为上升沿中断 下降沿中断和

随机推荐