NutzCN Logo
问答 beetl的isEmpty方法返回值不对啊?
发布于 2407天前 作者 qq_1d84c364 3253 次浏览 复制 上一个帖子 下一个帖子
标签:

我的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"
1 回复

isEmpty应该传变量,而非字符串吧

添加回复
请先登陆
回到顶部