这是否会使 MVC 设计模式失效?

我想知道使用控制器将本地学生(模型)拉到我的视图类中是否会使 MVC 设计模式无效。


供参考


我从来没有将我的学生模型导入到视图类中。


控制器


public void saveStudent(int selectedRow, Student studentChanged){

    studentList.getStudentList().set(selectedRow, studentChanged);

}

看法


Student currentStudent;

. . . .


public StudentDetailedUI(StudentCntrl studentCntrIn, int selectedRowIn) {

    studentCntrl = studentCntrIn;

    selectedRow = selectedRowIn;

    if (selectedRow >= 0) {

        currentStudent = studentCntrl.getStudent(selectedRow);

        initComponents();

        parseCurrentStudent();

    } else {

        initComponents();

        parseNewStudent();

    }

}

. . . .


JButton saveButton = new JButton("Save");

    saveButton.addActionListener((ActionEvent e) -> {

        if (selectedRow != -1){

            currentStudent.setFirstName(firstNameDisplayValue.getText());

            currentStudent.setLastName(lastNameDisplayValue.getText());

            currentStudent.setUniversity(universityDisplayValue.getText());

            currentStudent.setGpa(Double.parseDouble(gpaDisplayValue.getText()));

            StudentDetailedUI.this.studentCntrl.saveStudent(selectedRow, currentStudent);

            StudentDetailedUI.this.studentCntrl.getStudentListUI();

        }

        else {

            StudentDetailedUI.this.studentCntrl.addStudent(firstNameDisplayValue.getText() +", " +lastNameDisplayValue.getText() +", " +universityDisplayValue.getText() +", " +gpaDisplayValue.getText());

            StudentDetailedUI.this.studentCntrl.getStudentListUI();

        }

    });

我的预期功能是使用列表详细信息 GUI 更新列表中的现有学生。


万千封印
浏览 61回答 1
1回答

青春有我

只要有关更新的所有逻辑都保留在控制器中就可以了,最终您可以在视图中添加一些验证,但控制器仍然应该对联系持久层拥有最终决定权。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java