@Override public User selectUser(User user) { Session se = sf.getCurrentSession(); String hql = "select * from user where email=? and pwd=?"; User uu = (User) se.createSQLQuery(hql).addEntity(User.class).setParameter(0, user.getEmail()).setParameter(1, user.getPwd()).uniqueResult(); return uu; }
该查询语句hql查询出来的为object类型的一直在思考怎么转成User类型的,百度了一些资料,发现在
se.createSQLQuery(hql)后面添加
addEntity(User.class)就可以了
时间: 2024-11-02 05:00:07