jsp jdbc数据访问层设计
你好: 我有一个关于如何使用数据库(sql)设计和映射java中的对象类的问题。
例如,如果我有与数据库中的客户和订单表匹配的客户和订单类。如果我分别需要客户和订单信息,我只需使用 SQL 查询从数据库表中获取信息并将它们放入列表和列表中,并显示在前端应用程序中。 如果我需要同时显示客户和订单信息怎么办? 如何将 Customer 和 Order 对象放入一个数组列表中?
如果有人能帮助我在 jsp 或 asp.net 中回答这个问题,我将不胜感激。
谢谢
Hi:
I have a question about how to design and map object class in java with database(sql).
For example, if I have Customer and Order Class which match with Customer and Order Table in database. If I need the Customer and Order information separately, I simply use SQL query to fetch the information from database table and put them into List and List, and display in front end application.
What if I need to display to display both Customer and Order information at the same time?
How do put both Customer and Order object in one single arraylist?
If anyone can help me answering this question in either jsp or asp.net, i will be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先 - 不要在 jsp 中执行此操作。在 servlet/控制器调用的常规类中执行此操作。然后看看一些ORM——hibernate、eclipselink。但对于一个简单的项目来说可能太复杂了。另请参阅 commons-dbutils。
First - don't do this in a jsp. Do it in a regular class invoked by a servlet/controller. Then take a look at some ORM - hibernate, eclipselink. But it might be too complicated for a simple project. Also look at commons-dbutils.
一种可能的方法是构造一个传输对象,其中包括来自两个对象的必要信息,并将 TO 放入列表中。
检查 http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject。 html 和 http://en.wikipedia.org/wiki/Data_transfer_object 了解更多有关此模式的信息。
One possible approach is to construct a transfer object which includes the necessary information from both objects, and put the TO into a list.
Check http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html and http://en.wikipedia.org/wiki/Data_transfer_object for more information on this pattern.