日期:2014-05-17 浏览次数:20719 次
public Plans findByPlanName(String planName) {
return (Plans)this.getSession().createQuery("from Plans where title=?").setParameter(0, planName).list().get(0) ;
}
public Plans findByPlanName(String planName) {
List<Plans> plansList = (List<Plans>) this.getSession().createQuery("from Plans where title=?").setParameter(0, planName).list();
if (plansList.isEmpty())
return null;
return plansList.get(0) ;
}
Object obj = this.getSession().createQuery("from Plans where title=?").setParameter(0, planName).uniqueResult();
if(obj!=null){
return (Plans)obj;
}else{
//如果查询为记录,则做一些处理等等
return null;
}
//这样也可以,但是return前还是最好判断一下
Plans plans = (Plans)this.getSession().createQuery("from Plans where title=?").setParameter(0, planName).uniqueResult();
return plans;