String hql = "SELECT u.userName FROM User u WHERE u.userName = ?";
List userList=null;
userList=this.getHibernateTemplate().find(hql,user.getUserName());
用这个方法find(String hql,Object para)
hibernateTemplate里面需要封装sql语句的方法
public int excuteUpdateWithSQL(String sql, Object[] params) {
Session session = null;
Transaction tx = null;
Query query = null;
int row = 0;
try {
session = HibernateUtil.getSession();
tx = session.beginTransaction();
query = session.createSQLQuery(sql);
initParams(query, params);
row = query.executeUpdate();
tx.commit();
} catch (Exception e) {
HibernateUtil.rollbackTx(tx);
throw new DaoException(e);
} finally {
HibernateUtil.closeSession(session);
}
return row;
}
LS this.getHibernateTemplate().find(hql,user.getUserName());
这个方法是 加入了 spring 才有的
关注