为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

万千封印 2023-12-13 15:10:20
我想知道使用控制器将本地学生(模型)拉到我的视图类中是否会使 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 更新列表中的现有学生。
查看完整描述

1 回答

?
青春有我

TA贡献1784条经验 获得超8个赞

只要有关更新的所有逻辑都保留在控制器中就可以了,最终您可以在视图中添加一些验证,但控制器仍然应该对联系持久层拥有最终决定权。



查看完整回答
反对 回复 2023-12-13
  • 1 回答
  • 0 关注
  • 56 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信