当前位置 : 主页 > 手机开发 > ROM >

hql语句拼接模糊查询

来源:互联网 收集:自由互联 发布时间:2021-06-10
第一种: @Override public ListApply findByState(String apstate) { StringBuffer hql= new StringBuffer(); hql.append("from Apply app where 1=1"); if (apstate.length() != 0 apstate!=null){ hql.append(" and app.appState like ‘%"+apstate+"

第一种:

@Override
public List<Apply> findByState(String apstate) {
  StringBuffer hql= new StringBuffer();
  hql.append("from Apply app where 1=1");
  if (apstate.length() != 0 && apstate!=null){
    hql.append(" and app.appState like ‘%"+apstate+"%‘");
  }
  List<Apply> applies=(List<Apply>)this.getHibernateTemplate().find(hql.toString());
  return applies;
}

 

第二种:

@Override public List<Apply> findByState2(String apstate) {   String hql= "from Apply app where 1=1";   if (apstate.length() != 0 && apstate!=null){     hql=hql+" and app.appState like ‘%"+apstate+"%‘";   }   List<Apply> applies=(List<Apply>)this.getHibernateTemplate().find(hql);   return applies; }

网友评论