代码如下:

public List<Teacher> findTeacher(String str) {
  String hql="from Teacher where 1=1";
  hql+=" and tname like '%"+str+"%'"+" or tcode like '%"+str+"%'";
  Query query=getSession().createQuery(hql);
  List<Teacher> list=query.list();
  return list;
}

这是在SSH中要进行多个字段的模糊查询

如果报异常为:

unexpected token: % near line 1, column 53

则说明hql语句写错误了,重新检查