日期:2014-05-17  浏览次数:20808 次

用Struts+Hibernate 这样子得不到值是什么原因? 求大神指教

public List<TblRentInfo>findProjectByTitle(String title) throws Exception
{
List<TblRentInfo>  p= null;
List<TblRentInfo> pList=userDao.search("and title='"+title+"'");
if(pList.size()>0)
{
p=(List<TblRentInfo>) pList.get(0);
//System.out.println(p.add(pList.get(0)));
System.out.println("2222222");
System.out.println(p);
}
return p;

}


public  List<TblRentInfo> search(String condition) throws Exception
{
  List<TblRentInfo> userList=new ArrayList<TblRentInfo>();
  try
{
session=HibernateSessionFactory.getSession();
Query query=session.createQuery("from TblRentInfo where 1=1 "+condition);
userList=query.list();
System.out.println("1111111111");
}catch(Exception ex)
{
ex.printStackTrace();
throw new Exception("数据库错误");
}finally
{
HibernateSessionFactory.closeSession();
}
 
  return userList;
}

Hibernate Struts

------解决方案--------------------
p=(List<TblRentInfo>) pList.get(0);
p应该不是list 而是TblRentInfo
改为p=(TblRentInfo) pList.get(0);
------解决方案--------------------
userList=query.list();这一句不需要强转吗
------解决方案--------------------
List<TblRentInfo> pList=userDao.search("and title='"+title+"'");
pList 这个有值吗?这个有值的话,直接 return pList.get(0);