【问题标题】:Java MVC with File Input/Output [closed]具有文件输入/输出的 Java MVC [关闭]
【发布时间】:2014-04-04 03:49:05
【问题描述】:

我正在使用 java 中的 MVC 模式创建一个程序...但是我对如何正确执行文件输入感到非常困惑。

例如,我应该在 MAIN 中执行所有文件输入吗? ..我试过但它变得混乱,我不确定是否有一种“统一”的方式来执行 MVC 模式的文件输入。这是针对 OOP 分配 btw 的。谢谢你。

【问题讨论】:

  • 您几乎可以肯定不应该在 main 中进行任何 I/O,但至于任何其他问题,这太宽泛了,无法提出任何明智的建议。
  • 感谢您的评论,我知道 IO 现在不应该进入 main 并且我已经取得了明智的进步。神速。

标签: java oop model-view-controller file-io input


【解决方案1】:

对于理论问题,答案将是理论的。

MVC 表示模型视图控制器

Model - Model represents the layer that is closely related to data. Say if you want to persist a Employee object, you have a Employee POJO carrying the Employee data.

View - View represents the visualization of the data that model contains.

Controller - Controller acts on both Model and view. It controls the data flow into model object and updates the view whenever data changes. It keeps View and Model separate.

在您的情况下,文件输入过程 - 您是什么意思?文件作为输入发送,您需要将文件保存在数据库中吗?

不是展示 MVC 模式的好用例。然而..为了您的理解

View - you can have a File Upload page

Controller - The class that route the control from view to a Java class that performs File Read, and performs business logic on the input file

Model - A class that has database connection setup, and has a method that accepts the final formatted File and store to the database.

经验丰富的人,如果你有这种感觉,请纠正我

【讨论】:

  • 感谢您的帖子,它帮助很大。神速。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-09
  • 2011-01-19
相关资源
最近更新 更多