mybatis里的页面的if标签怎么用

如题所述

第1个回答  2019-11-30
[html]
view
plain
copy
如果
userqueryvo中传入查询条件,再进行sql拼接
test中usercustom.username表示从userqueryvo读取属性值
and
username
like
'%${usercustom.username}%'
and
sex
=
#{usercustom.sex}
根据id集合查询用户信息
最终拼接的效果:
select
id
,username
,birthday
from
user
where
username
like
'%小明%'
and
id
in
(16,22,25)
collection:集合的属性
open:开始循环拼接的串
close:结束循环拼接的串
item:每次循环取到的对象
separator:每两次循环中间拼接的串
#{id}
select
id
,username
,birthday
from
user
where
username
like
'%小明%'
and
(id
=
16
or
id
=
22
or
id
=
25)
<foreach
collection="ids"
open="
and
(
"
close=")"
item="id"
separator="or">
id
=
#{id}

还有很的查询条件
[html]
view
plain
copy
select
id,username,birthday
from
user
where标签相当
于where关键字,可以自动去除第一个and
引用sql片段,如果sql片段和引用处不在同一个mapper必须前边加namespace
下边还有很其它的条件
<include
refid="其它的sql片段">
相似回答
大家正在搜