日期:2014-05-20  浏览次数:20763 次

Action取不出数据
public class ResultAction extends ActionSupport{
private List<StudentLesson> studentlessonlist;


@Override
public String execute() throws Exception {
studentlessonlist=new ArrayList<StudentLesson>();
DbOperate db=new DbOperate();
List list=db.queryStudentLesson();
Iterator iterator=list.iterator();
while(iterator.hasNext()){
StudentLesson studentlesson=(StudentLesson) iterator.next();
System.out.println(studentlesson.getId());
System.out.println(studentlesson);
System.out.println(studentlesson.getRes1());
System.out.println(studentlesson.getRes2());
System.out.println(studentlesson.getRes3());
System.out.println(studentlesson.getRes4());
System.out.println(studentlesson.getRes5());
System.out.println(studentlesson.getRes6());
studentlessonlist.add(studentlesson);
}


return SUCCESS;
}


public List<StudentLesson> getStudentlessonlist() {
return studentlessonlist;
}


public void setStudentlessonlist(List<StudentLesson> studentlessonlist) {
this.studentlessonlist = studentlessonlist;
}

这是DbOperate的类
public List queryStudentLesson(){//查询所有成绩单
List list=null;
String str="from StudentLesson ";
Transaction tx=null;
Session session=HibernateSessionFactory.getSession();
try {
tx=session.beginTransaction();
tx.begin();
Query query=session.createQuery(str);
list=query.list();
tx.commit();
} catch (HibernateException e) {
if(tx!=null){
tx.rollback();
}
throw e;
}
return list;
}
用test类查询可以查询到
public static void main(String[] args) {
DbOperate db=new DbOperate();
List list=db.queryStudentLesson();
Iterator iterator=list.iterator();
while(iterator.hasNext()){
StudentLesson studentlesson=(StudentLesson) iterator.next();
System.out.println("name:"+studentlesson.getStudent().getName()+"lesson:"+studentlesson.getLesson().getName()
+"成绩1:"+studentlesson.getRes1()+"成绩2:"+studentlesson.getRes2()+"成绩3:"+studentlesson.getRes3()
+"成绩4:"+studentlesson.getRes4()+"成绩5:"+studentlesson.getRes5()
+"成绩6:"+studentlesson.getRes6());

}


}
可以正常显示
但用网页,studentlesson除了getId可以显示,其他属性都为null

------解决方案--------------------
看一下你在execute()的list是否为空。