【发布时间】:2017-01-09 08:07:47
【问题描述】:
我正在使用 Spring 集成的“int-jdbc:inbound-channel-adapter”从数据库中获取记录。但是,在我获取记录后,我还需要更新 2 列 1) 状态栏 2) 时间戳列
更新状态栏不是问题,因为我可以在 xml sn-p 下面使用
<int-jdbc:inbound-channel-adapter query="select * from item where status=2"
channel="target" data-source="dataSource"
update="update item set status=10 where id in (:id)" />
但是当我尝试更新时间戳时,它不起作用
<int-jdbc:inbound-channel-adapter query="select * from item where status=2"
channel="target" data-source="dataSource"
update="update item set status=10,timestamp=:timestamp where id in (:id)"
update-sql-parameter-source-actory="timestampUpdaterSqlParameterSourceFactory">
<int-jdbc:inbound-channel-adapter>
<bean id="timestampUpdaterSqlParameterSourceFactory"
class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory" >
<property name="parameterExpressions">
<map>
<entry key="timestamp" value="@now"/>
</map>
</property>
</bean>
<bean id="now" scope="prototype" class="java.sql.Timestamp">
<constructor-arg value="#{ T(java.lang.System).currentTimeMillis()}" />
</bean>
我们可以使用 DB 级别的方法来设置时间,例如 sysdate 用于 oracle,但我不热衷于在代码中使用 DB 特定的方法进行测试(H2 DB 用于测试)
非常感谢任何帮助
谢谢
【问题讨论】:
-
您知道,刚刚使用 HSQL 测试了您的代码 - 运行良好。也许
timestamp是 H2 的关键词?你觉得问题如何?