读书人

用Struts+Hibernate 这么子得不到值是

发布时间: 2013-06-19 10:26:41 作者: rapoo

用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;
}

用Struts+Hibernate 这么子得不到值是什么原因? 求大神指教 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);

读书人网 >Java Web开发

热点推荐