Struts 2 - 添加到嵌套集合

发布于 2024-10-15 04:42:38 字数 831 浏览 2 评论 0原文

所以我有一个学生类,它是我的动作类

import java.util.Vector;

public class Student extends ActionSupport{
    private Vector<AcaClass> classes;

    public Student(){}

    public Vector<Class> getClasses() {
        return classes;
    }

    public void setClasses(Vector<Class> classes) {
        this.classes = classes;
    }

    public void addClass(AcaClass acaClass){
            this.classes.add(acaClass)
    }  


}

,并且我有一个 AcaClass

public class AcaClass {

    private Term term;
    private String grade;
    private String description;
    //public 

    public AcaClass(){}

        //Getters and setters for all data members
}

是否可以将一个类添加到学生的类集合中?我觉得我必须提交表单,然后进行一些类型转换才能将表单字段转换为 AcaClass bean。如果可能的话,我可以进入多少级别的集合(即,将一个班级添加到大学集合中的学院集合中的学生集合中)

So I have a student class that is my action class

import java.util.Vector;

public class Student extends ActionSupport{
    private Vector<AcaClass> classes;

    public Student(){}

    public Vector<Class> getClasses() {
        return classes;
    }

    public void setClasses(Vector<Class> classes) {
        this.classes = classes;
    }

    public void addClass(AcaClass acaClass){
            this.classes.add(acaClass)
    }  


}

and I have a AcaClass

public class AcaClass {

    private Term term;
    private String grade;
    private String description;
    //public 

    public AcaClass(){}

        //Getters and setters for all data members
}

Is it possible to add a class to to the student's collection of classes? I feel like that I would have to do a form submission and then some type conversion to turn the form fields into the AcaClass bean. If this is possible, how many levels of collections can I go (i.e. Add a class to a collection of students thats in a collection of colleges thats in a collection of universities)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七颜 2024-10-22 04:42:38

OGNL 将为您进行转换。

看看这个非常相似的问题。 Struts2 - 编辑复合对象

OGNL will do the conversion for you.

See this very similar question. Struts2 - Edit Composite Object

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文