public class EmployeeDaoImpl extends HibernateDaoSupport implements EmployeeDao{ //DAO中根据用户名和密码查询用户的方法(HQL查询) @Override public Employee findByUsernameAndPassword(Employee employee) { String hql="from Employee where username = :username and password = :password"; List<?> list=this.getHibernateTemplate().find(hql, employee.getUsername(),employee.getPassword()); if (list.size()>0) { return (Employee) list.get(0); }else { return null; } } }
代码如上,报500错误……实在解决不来,求各位帮帮忙
使用的hibernate版本是5.3.2
getHibernateTemplate().findByNamedParam(hql,{"username","password"},{第一个值,第二个值}) 顺便提一句更新后的?变为?1 风格变了需要在后边加上序号
String hql=
"from Employee where username = :username and password = :password"
;
改
String hql=
"from Employee where username = ?0 and password = ?1
;
"from Employee where username = ? and password = ?" 这样写试试?