Mybatis中动态sql常用标签

本文介绍了Mybatis动态SQL的几个核心标签:if、choose(when、otherwise)、trim(where、set)、foreach和bind。if标签用于条件判断,choose标签类似switch-case结构,trim标签灵活处理SQL关键字,foreach实现集合遍历,bind标签则用于自定义上下文变量,尤其在模糊查询中有重要作用。
摘要由CSDN通过智能技术生成

Mybatis动态SQL中常用的标签有:if标签、choose(when、otherwise)标签、trim(where、set)标签、foreach标签。以下展开介绍:

if标签

if是常用的判断语句,常与test属性连用,或者与concat属性连用。

<select id="getStudent" parameterType="string" resultMap="student">
	select * from student
	where 1=1
	<if test="name != null">
		and NAME = #{
   name,jdbcType=VARCHAR}
	</if>
</select>

或者与concat连用,进行模糊匹配

<select id="getStudent" parameterType="string" resultMap="student">
	select * from student
	where 1=1
	<if test
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值