日期:2014-05-17 浏览次数:20714 次
String sql = "from com.core.mvc.po.Teacher t where t.name like :name";
String sql = "select new com.core.mvc.po.Teacher(t.id,t.name) from com.core.mvc.po.Teacher t where t.name like :name";
public List<Buyer> login(final Buyer buyer) {
// TODO Auto-generated method stub
/*String sql = "from Buyer as b where b.username = ? and b.password = ?";
List<Buyer> list = this.getHibernateTemplate().find(sql,new Object[]{buyer.getUsername(),buyer.getPassword()});
return list;*/
return (List<Buyer>)this.getHibernateTemplate().execute(new HibernateCallback() {
String Hql="from Buyer b where b.username=? and b.password=?";
public Object doInHibernate(Session session) throws HibernateException,
SQLException {
// TODO Auto-generated method stub
List<Buyer> list=new ArrayList<Buyer>();
try {
Query q=session.createQuery(Hql);
q.setString(0, buyer.getUsername());
q.setString(1, buyer.getPassword());
list=q.list();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return list;
}
});
}