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;
}HibernateStruts
SQL 语句查出来了。 是我要的查的语句,但是就是返回值收不到,p=(List<TblRentInfo>) pList.get(0); P是空值
SQL 语句查出来了。 是我要的查的语句,但是就是返回值收不到,p=(List<TblRentInfo>) pList.get(0); P是空值你的库里面有对应的数据??直接copy到你的数据库去查,没数据当然查不到呀,前提你的sql没问题!
SQL 语句查出来了。 是我要的查的语句,但是就是返回值收不到,p=(List<TblRentInfo>) pList.get(0); P是空值你的库里面有对应的数据??直接copy到你的数据库去查,没数据当然查不到呀,前提你的sql没问题!
public List<TblRentInfo>findProjectByTitle(String title) throws Exception
{
List<TblRentInfo> p= null;
List<TblRentInfo> pList=userDao.search("and title='"+title+"'");
System.out.println("22222222");
if(pList.size()>0)
{
p=(List<TblRentInfo>) pList.get(0);
//System.out.println(p.add(pList.get(0)));
System.out.println("33333");
System.out.println(p);
}
System.out.println("4444444");
return p;
}
我这样调试了一下 后台显示结果为:
Hibernate: select tblrentinf0_.id as id1_.....
1111111111
[]
22222222
4444444
也就是说 没有进入if 语句。 所以P 还是个null 值。
SQL 语句查出来了。 是我要的查的语句,但是就是返回值收不到,p=(List<TblRentInfo>) pList.get(0); P是空值你的库里面有对应的数据??直接copy到你的数据库去查,没数据当然查不到呀,前提你的sql没问题!数据库里有对应的数据,查出来的sql是正确的 试了。
SQL 语句查出来了。 是我要的查的语句,但是就是返回值收不到,p=(List<TblRentInfo>) pList.get(0); P是空值你的库里面有对应的数据??直接copy到你的数据库去查,没数据当然查不到呀,前提你的sql没问题!数据库里有对应的数据,查出来的sql是正确的 试了。findProjectByTitle这个方法的写法太繁琐了,而且p=(List<TblRentInfo>) pList.get(0);这句话你不觉得有问题?
SQL 语句查出来了。 是我要的查的语句,但是就是返回值收不到,p=(List<TblRentInfo>) pList.get(0); P是空值你的库里面有对应的数据??直接copy到你的数据库去查,没数据当然查不到呀,前提你的sql没问题!数据库里有对应的数据,查出来的sql是正确的 试了。其实就是这样的:
public String findHouserTitle(){
try{
findList= userService.findProjectByTitle(houseUser.getTitle());
System.out.println("");
return this.SUCCESS;
}catch(Exception ex){
this.addActionError(ex.getMessage());
return this.ERROR;
}
}调用fandfindProjectByTitle方法
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= pList.get(0);
}
return pList;
}
然后 调用search方法 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();
}catch(Exception ex)
{
ex.printStackTrace();
throw new Exception("数据库错误");
}finally{
HibernateSessionFactory.closeSession();
}
return userList;
}
}
SQL 语句查出来了。 是我要的查的语句,但是就是返回值收不到,p=(List<TblRentInfo>) pList.get(0); P是空值你的库里面有对应的数据??直接copy到你的数据库去查,没数据当然查不到呀,前提你的sql没问题!数据库里有对应的数据,查出来的sql是正确的 试了。p=(List<TblRentInfo>) pList.get(0); 我就是觉得这行有问题 但是不知道怎么改 。反正就是把SQL查询出来的结果对象 怎么放到findHouserTitle()中的 findList 去就行了。 sql语句已经确定没问题了 我试过了。
SQL 语句查出来了。 是我要的查的语句,但是就是返回值收不到,p=(List<TblRentInfo>) pList.get(0); P是空值你的库里面有对应的数据??直接copy到你的数据库去查,没数据当然查不到呀,前提你的sql没问题!数据库里有对应的数据,查出来的sql是正确的 试了。我懂了,终于知道问题出在那了纠结了半天是的 sql 语句是对的,但是查出来的结果无值,因为条件没带过去。。 谢了O(∩_∩)O~
直接改成List<TblRentInfo> userList = null;
List<TblRentInfo> pList.get(0)返回的应该是TblRentInfo类型的,p= pList.get(0);这句p也是一个实体类型,为啥要转成一个List?
p应该不是list 而是TblRentInfo
改为p=(TblRentInfo) pList.get(0);
pList 这个有值吗?这个有值的话,直接 return pList.get(0);