MyBatis 动态sql语句:
1:if:if:if标签test="xx"表示满足的条件,xxxxx标识满足条件即执行的语句
xxxxx
2:if+where:举例根据条件查询用户表的信息where标签里如果有返回值,则在最前面添加where并将前缀为and或者or去掉
select
*
from Users
and name=#{name}
and age=#{age}
3:if+set:一般用于修改操作,在最前面添加set并取出后缀 “,”
update Users
name=#{name},
age=#{age},
where id=#{id}
4:choose+when+otherwise(相当余java的switch),只能执行其中一个条件
select * from Users
and name=#{name}
and age=#{age}
and id=#{id}
5:foreach:用于查询条件为不确定数量的集合 collection="ids"表示传入集合自己改过后的名字item="id"表示将其赋给id
select * from Users
#{id}