我的sql文件,只有searchText不为空才应该加进去啊?
select distinct a.* from tdocument a
left join tdocumentlabelmap b on a.id = b.documentId
left join tcommonloginuser c on a.createuserid = c.id
where
a.companyId = @companyId
<%if(!isEmpty("searchText")){%>//注意这行
and (
a.title like @searchText
or c.nickname like @searchText
)
<%}%>
<%if(has("labelId")){%>
and (
b.labelId in(
SELECT DISTINCT x.id FROM tcommonlabel x
LEFT JOIN tcommonlabelusermap y on x.id = y.labelId
LEFT JOIN tcommonloginuser z on z.id = y.loginUserId
where x.id in(
select * from (
select id from tcommonlabel a
left join tcommonlabelusermap b on a.id = b.labelId
where b.loginUserId = @loginUserId
) temp
) and x.companyId = @companyId
) or a.createUserId = @loginUserId
)
<%}else{%>
and b.labelId = @labelId
<%}%>
order by a.status asc,a.toplevel desc,a.toptime desc,a.createTime desc
打印出的sql
For example:> "select distinct a.* from tdocument a
left join tdocumentlabelmap b on a.id = b.documentId
left join tcommonloginuser c on a.createuserid = c.id
where
a.companyId = 1
and (
a.title like ''
or c.nickname like ''
)
and (
b.labelId in(
SELECT DISTINCT x.id FROM tcommonlabel x
LEFT JOIN tcommonlabelusermap y on x.id = y.labelId
LEFT JOIN tcommonloginuser z on z.id = y.loginUserId
where x.id in(
select * from (
select id from tcommonlabel a
left join tcommonlabelusermap b on a.id = b.labelId
where b.loginUserId = 1
) temp
) and x.companyId = 1
) or a.createUserId = 1
)
order by a.status asc,a.toplevel desc,a.toptime desc,a.createTime desc LIMIT 0, 10"