struts 2列表迭代

时间:2017-01-13 08:46:14

标签: spring struts2

我是新struts我有一个前端使用struts和一个后端使用spring dao与实体类型pojo类,我想返回system.code中的学生列表我已经尝试过附加在下面我只是获取值我将列表设置为表格类。

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

acessslist的动作类代码如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";
    }
}

1 个答案:

答案 0 :(得分:1)

如果您想在不使用第二种方法(setStudent(ArrayList<StudentEntity> studentList))的情况下获取学生列表 您必须使用studentList.add(student);这样的第一种方法将您的学生添加到您的arraylist中;

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