java web应用程序-用于显示带有sql连接的列表的模型设计
我正在编写一个 javabean,想知道它是否应该包含属性来设置从 sql 连接获取的值? 假设我有产品和订单
数据库表。这些也是我的 java bean 名称。
现在我想显示所有产品的列表,但除了所有产品属性之外,我还希望有列显示上次购买日期
和上次购买者
我的数据库查询要获取产品列表,需要进行联接来收集附加信息。在 Product.java 模型中为“上次购买日期和上次购买者”设置 setter 和 getter 似乎不正确。我可能想要第三列,因此不断向我的 bean 添加新列是没有意义的。
你怎么办?当我需要在我的视图中显示模型列表时,我似乎遇到了这种情况。
I am authoring a javabean and would like to know if it should include properties to set values obtained from a sql join?
Say I have database tables for Products and Orders.
These are also my java bean names.
Now I want to display a list of all products but in addition to all the product properties, I want to have columns to display last purchase date
and last purchased by
My db query to get the product list would need to do joins to gather the additional info. It does not seem correct to have setters and getters for `last purchase date and last purchased by' in Product.java model. I may want to have a 3rd column so constantly adding new columns to my bean doesn't make sense.
How do you go about this? I seem to encounter this when needing to display lists of models in my view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在产品中有一张地图。触发 sql 后,将连接结果存储为 Map 中的键值对。 K=lastpurchasedby(columnName) 且 V= 值
所以不需要添加单独的属性。它们都以键值对的形式出现。
Have a Map in Product. Upon firing the sql, store hte results of the join as key value pair in the Map. K=lastpurchasedby(columnName) and V= the value
So no need to add individual attributes. They all come in key-value pairs.