struts 2 次列表迭代
struts 2 list iteration
我是新手 struts 我有一个使用 struts 的前端和一个使用 spring dao 实体类型 pojo class 的后端,我想 return 我试过的 system.code 中的学生列表附在下面 我只有在将列表设置为 class.
时才能获取值
public class Studentform {
private StudentEntity student;
public StudentEntity getStudent() {
return student;
}
public void setStudent(StudentEntity student) {
this.student = student;
}
public void setStudent(ArrayList<StudentEntity> studentList) {
// TODO Auto-generated method stub
this.studentList=studentList;
}
}
action class 访问列表的代码为 studform.setStudent(studentList);
public class StudentAction extends ActionSupport implements
ModelDriven<Studentform> {
ArrayList<StudentEntity> studentList=new ArrayList<StudentEntity>();
//geters and setter for studentList
public String stdus() {
HttpSession session = ServletActionContext.getRequest().getSession();
String id = (String) session.getAttribute("userid");
studentList=controller.getStudentProfile();
studform.setStudentList(studentList);
System.out.println(studentList.size());
return "SUCCESS";
}
}
如果你想不使用第二种方法获取学生列表(setStudent(ArrayList<StudentEntity> studentList))
你必须在你的第一个方法中将你的学生添加到你的arraylist中,比如studentList.add(student);
something like this;
public class Studentform {
private StudentEntity student;
private List<StudentEntity> studentList = new ArrayList();
public StudentEntity getStudent() {
return student;
}
public void setStudent(StudentEntity student) {
this.student = student;
studentList.add(student);
}
//add your list getter method here
我是新手 struts 我有一个使用 struts 的前端和一个使用 spring dao 实体类型 pojo class 的后端,我想 return 我试过的 system.code 中的学生列表附在下面 我只有在将列表设置为 class.
时才能获取值public class Studentform {
private StudentEntity student;
public StudentEntity getStudent() {
return student;
}
public void setStudent(StudentEntity student) {
this.student = student;
}
public void setStudent(ArrayList<StudentEntity> studentList) {
// TODO Auto-generated method stub
this.studentList=studentList;
}
}
action class 访问列表的代码为 studform.setStudent(studentList);
public class StudentAction extends ActionSupport implements
ModelDriven<Studentform> {
ArrayList<StudentEntity> studentList=new ArrayList<StudentEntity>();
//geters and setter for studentList
public String stdus() {
HttpSession session = ServletActionContext.getRequest().getSession();
String id = (String) session.getAttribute("userid");
studentList=controller.getStudentProfile();
studform.setStudentList(studentList);
System.out.println(studentList.size());
return "SUCCESS";
}
}
如果你想不使用第二种方法获取学生列表(setStudent(ArrayList<StudentEntity> studentList))
你必须在你的第一个方法中将你的学生添加到你的arraylist中,比如studentList.add(student);
something like this;
public class Studentform {
private StudentEntity student;
private List<StudentEntity> studentList = new ArrayList();
public StudentEntity getStudent() {
return student;
}
public void setStudent(StudentEntity student) {
this.student = student;
studentList.add(student);
}
//add your list getter method here