如何创建从数据库表设置其属性的Spring Bean配置文件 [英] How to create spring bean config file that sets its properties from a database table

查看:128
本文介绍了如何创建从数据库表设置其属性的Spring Bean配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数据列的excel文件,我的目标是从这些数据中创建对象,这些对象之间具有相互关系,并将其完全初始化的父对象发送到企业应用程序以进行验证和插入

I have an excel file that contain columns of data, my target is to create objects out of this data, where these objects have relationships with each other, and send their fully initialized parent object to an enterprise application for validation and insertion into the database.

比方说,我设法将所有这些excel数据插入到暂存(第一轮)数据库中。有什么方法可以创建一个可以创建对象层次结构的bean配置文件,其中每个对象都有从数据库列中检索到的属性?

Let's say I manage to insert all this excel data into a staging(first round) database. Is there any way that I could create a bean config file that can create object hierarchies, where each object has properties retrieved from a database column?

首先:

Column 1=> 1 2 3 5 6 7
Column 2=> a v d e f g
Column 3=> Some primary key column.







<bean name="myDomainObject" class="abcd.pqr.DomainObject1">
     <property name="column1" value="???" />
     <property name="column2" value="???" />
</bean>

我想创建一个配置文件,其中包含6个域对象,并且值

I would like a config file to be created that has, say 6 domain objects, and the values come from the database.

下一步可能是尝试创建一个复杂的对象层次结构,其中 myDomainObject 可以嵌套在其中一些 myParentDomainObject

Next step could be trying to create a complex object hierarchy, where myDomainObject could be nested inside some myParentDomainObject.

我的目的是从数据库中创建域对象,这样我的测试用例就可以轻松实现点击具有完整配置的测试对象的应用程序。它也可以用于通过API加载数据。

My intention is to create domain objects out of a database, so that my test cases can easily hit the application, with fully configured test objects. It could also be used to load data through an API.

推荐答案

我认为Spring是在此工作的错误工具。如果您在数据库中有对象,为什么不使用JPA / Hibernate和有意义的数据模型来帮您呢?

Spring is the wrong tool for the job here, I think. If you have the objects in a database, why not use JPA/Hibernate and a meaningful data model to do this for you?

您将创建bean(在任何对象中)绘制它们形成的图形),然后用一些JPA注释对其进行注释,然后让您的JPA实现执行将它们从数据库拉入对象图的工作。

You would create your beans (in whatever object graph they form), then annotate them with some JPA annotations, and let your JPA implementation do the work of pulling them from the DB into your object graph.

这篇关于如何创建从数据库表设置其属性的Spring Bean配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆