getHibernateTemplate().find(hql)返回值及引用传值问题

//StudentDAO中的方法
public boolean getPoList(String hql, List poList){
boolean result = false;
try{
poList = getHibernateTemplate().find(hql);
result = true;
}catch(Exception ex){
ex.printStackTrace();
}
return result;
}

//StudentService中的方法
public boolean A{
boolean result = false;
 String hql = "FROM Student WHERE isDel='N'";
List poList = new ArrayList();
result = studentDAO.getPoList(hql, poList);
//使用poList的操作省略。。。。。。
return result;
}

debug时在getPoList方法中poList里面有内容,到达方法A时,poList为什么为没有内容(里面全部存放的是null)

  1. 你是从A方法到的StudentDAO对应的方法,在A方法中你把断点设在return那一行,执行了StudentDAO在看看有没有数据
  2. 他的运行应该是 先从A一步一步往下走result = studentDAO.getPoList(hql, poList);到了这一步这个集合依然是空的 只有执行了 走到下一步这个集合如果从studentDAO得到了检索出来的数据那么这个集合才会有数据。否则也是空

我刚才看了一下,断点打到A方法的return处,poList的内容还是null

//StudentDAO中的方法
public boolean getPoList(String hql, List poList){
boolean result = false;
try{
poList = getHibernateTemplate().find(hql);
result = true;
}catch(Exception ex){
ex.printStackTrace();
}
return result;
}
------------------------改成----------------------------
//StudentDAO中的方法
public boolean getPoList(String hql, List poList){
boolean result = false;
List tempPoList=new ArrayList();
try{
tempPoList = getHibernateTemplate().find(hql);

for(int i=0;i<tempPoList.size();i++){
poList.add(tempPoList.get(i));
}
result = true;
}catch(Exception ex){
ex.printStackTrace();
}
return result;
}
=============这样试试=======
貌似使用等号 poList = getHibernateTemplate().find(hql);不行,使用list的add方法。

去看下JAVA的形参传递方式吧!