帆软查询条件

1.当查询条件为空时,查询所有数据;当查询条件不为空时,根据条件查询。

 语句1:select  * from  mainInfo where 1=1 ${if(len(mainInfoId) == 0,"","and mainInfoId = '" + mainInfoId + "'")} 

 语句2: select  * from  mainInfo where 1=1 ${if(len(mainInfoId) == 0,nofilter,"and mainInfoId = '" + mainInfoId + "'")} 

在 ${if(len(mainInfoId)>0,nofilter,"1=1")}  中,nofilter 表示参数 mainInfoId 为空,就不过滤;若不为空则以参数值进行过滤。

语句1与语句2 查询结果一致,2个sql都可以使用。

原文地址:https://www.cnblogs.com/ming-blogs/p/10895510.html