English 中文(简体)
数据库到GUI或数据库到对象到GUI
原标题:Database to GUI or Database to Object to GUI

I am making kind of CRUD application (Java GUI , MYSQL) Should I :

  • load data from database to List (for example) and then List to GUI
  • load data from database to Object(with attributes like SQL table) and Object to GUI

我只是瘫痪,还是真的需要另一个目标?

最佳回答

理想情况下,为了严格分离关注点,您会希望保持两个模型的分离。

如果您正在开发MVC(即Model,View,Controller)丰富的客户端应用程序,则应使用单独的模型绑定到GUI /表单,这称为视图模型,其目的是呈现,捕获和验证来自GUI的数据。理想情况下,您将把这些数据复制到域或数据模型中,这是您要持久化的模型。

这真的取决于应用程序是否要走那么远,对于那些只用于完成简单任务的1-2屏幕即可扔掉的应用程序,我真的不太在意,但是这种方法在开发大型复杂应用程序时确实非常有帮助。

问题回答

理论上,您可以两者都做,但选择第二种方法将使稍后添加一些非基本功能(例如验证)更加容易。

我猜它很大程度上取决于你要用数据做什么以及有多少数据。

例如,如果您只打算在某种表格结构的 GUI 上展示它,您可能不需要对象。但是,如果您想以非表格化的方式呈现数据,或者想要修改数据,或者数据也有行为附加,那么对象是更好的选择。但是,如果您需要处理表格中的 300 万行,您就不想用对象占用内存了...





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签