mybatis(5)

数据库相关不区分大小写,类相关需要考虑大小写
动态sql
a.

<select id="queryStudentByNameOrAgeWithSQLTag" parameterType="student"
	resultType="student">
	select stuNo,stuName,stuAge from student where 1=1
	<if test="stuName !=null and stuName!='' ">
	and stuname=#{stuName}
</if>
	<if test="stuAge !=null and stuAge!=0 ">
	and stuage=#{stuAge}
	</if>

</select>

1=1是为了后面可以跟and,防止有数字为空
b.

<select id="queryStudentByNameOrAgeWithSQLTag" parameterType="student"
	resultType="student">
	select stuNo,stuName,stuAge from student
	
	<where>
	
	<if test="stuName !=null and stuName!='' ">
	stuname=#{stuName}
</if>
	<if test="stuAge !=null and stuAge!=0 ">
	and stuage=#{stuAge}
	</if>
	
	</where>

</select>

标签只能自动处理标签的第一个and

标签
ids={1,2,5}
select stuno,stuname from student where stuno in(1,2,5)

迭代的类型:数组、集合、属性(Grade类:List ids)

属性:Grade类:List ids

<select id="queryStudentWithNoswithGrade" parameterType="grade"
	resultType="Student">
	select * from student
	<where>
		<if test="stuNos!=null and stuNos.size>0">
			<foreach collection="stuNos" open=" and stuno in(" close=")"
				item="stuNo" separator="; ">
				#{stuNo}
			</foreach>
		</if>
	</where>
</select>

数组:
无论编写代码时,传递的时参数名必须用array代替该数组。
集合:
无论编写代码时,传递的时参数名必须用list代替该数组。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值