问题描述
- hql拼接语句时的空格问题
-
下面两段代码是我拼接hql语句的两种:
1、if(hql.indexOf("where")==-1){
hql += " where archiveTime is not null and netType = '"+netType+"' ";
}else{
hql += " and archiveTime is not null and netType = '"+netType+"' ";
}if(companyName!=null&&!"".equals(companyName)){ hql+="and Business_.lowerName.customer.name1 like '%"+companyName+"%'"; }
下面是第二种:
2、 if(hql.indexOf("where")==-1){
hql += " where archiveTime is not null and netType = '"+netType+"'";
}else{
hql += " and archiveTime is not null and netType = '"+netType+"'";
}if(companyName!=null&&!"".equals(companyName)){ hql+=" and Business_.lowerName.customer.name1 like '%"+companyName+"%'"; }
乍一看两个是没有区别的,但是注意看会发现,第一个在netType后面加了空格,第二个是在and 之前加的空格。两种运行的第一种是正确的,第二种是错误的。网上找不到资料,忘各位大神帮忙分析下原因。
时间: 2024-10-22 17:47:00