【发布时间】:2016-03-04 08:16:12
【问题描述】:
我是 Apache Camel 的新手。我有下面的 XML,我从一个安静的 api 中使用它。我已经使用 JaxB 为其生成了四个对象。即 ConsumerList.java、Consumer.java、Address.java 使用 apache camel。
<consumer_list>
<consumer>
<name>John</name>
<address>
<street>13 B</street>
<city>Mumbai</city>
</address>
</consumer>
<consumer>
<name>Paul</name>
<address>
<street>82 A</street>
<city>Delhi</city>
</address>
</consumer>
</consumer_list>
现在我的要求是将这 4 个对象保存到数据库。以下是我从 camel-context.xml 出发的路线:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/firstdb"/>
<property name="username" value="postgres"/>
<property name="password" value="xyz"/>
</bean>
<!-- configure the Camel SQL component to use the JDBC data source -->
<bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="dataSource"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="generateOrder-route">
<from uri="timer://foo?fixedRate=true&period=60000"/>
<setHeader headerName="Exchange.HTTP_QUERY">
<constant>dept=7&name=Johnson&offset=0&limit=200</constant>
</setHeader>
<to uri="http://example.com/ibp/api/v3/business_partners/search"/>
<unmarshal>
<jaxb prettyPrint="true" contextPath="target.jaxb.beans"/>
</unmarshal>
<to ???"/>
</route>
</camelContext>
我已经解组了这些对象,但我不知道如何将其插入数据库。
【问题讨论】:
-
我看过那些。我唯一的问题是我不确定应该在插入语句中输入哪些值。我的意思是 xml 中的地址字段具有街道和城市属性。相同的地址类由 jaxb 创建。现在我如何获取街道和城市属性并放入插入语句。
-
这里有很多数据库例子你可以先学习一下:github.com/apache/camel/tree/master/examples
标签: java xml jaxb apache-camel