使用 where 1=1 恒等式
然后 后面有拼接时 再添加 and String hql="from PersonInfo where 1=1 ";
if (lsName != null) {
hql=hql+" and name='"+ lsName+ "'";
}
if (ssdw != null ) {
hql=hql+" and ssdw='"+ssdw+"'";
}
if (zyzh != null){
hql=hql+" and zyzh='"+zyzh +"'";
}
if (zgsfj != null){
hql=hql+" and zgsfj='"+zgsfj+"'";
}
然后 后面有拼接时 再添加 and String hql="from PersonInfo where 1=1 ";
if (lsName != null) {
hql=hql+" and name='"+ lsName+ "'";
}
if (ssdw != null ) {
hql=hql+" and ssdw='"+ssdw+"'";
}
if (zyzh != null){
hql=hql+" and zyzh='"+zyzh +"'";
}
if (zgsfj != null){
hql=hql+" and zgsfj='"+zgsfj+"'";
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货