【问题标题】:Spring integration jdbc array update query spel expressionSpring集成jdbc数组更新查询spel表达式
【发布时间】:2018-08-17 14:05:18
【问题描述】:

我正在尝试为我的JdbcPollingChannelAdapter 创建一个“更新查询”,给定以下工作流程:

  1. 从数据库中选择500条A类记录
  2. 用读取的最后一条记录(位置 500 处的记录)的值更新另一个表中的 1 行

但我无法解决它,因为我一直在尝试使用 spring-el 来查找值。

通过调试,我达到了JdbcPollingChannelAdapterexecuteUpdateQuery方法,

void executeUpdateQuery(Object obj) {
        SqlParameterSource updateParameterSource = this.sqlParameterSourceFactory.createParameterSource(obj);
        this.jdbcOperations.update(this.updateSql, updateParameterSource);
    }

其中Object obj 是一个包含 500 条 A 类型记录的 ArrayList

这是我最好的比赛:

UPDATE LAST_EVENT_READ SET SEQUENCE=:#root[499].sequence, EVENT_DATE=:#[499].eventDate

谁能帮帮我?

附: A型有sequence和eventDate属性

【问题讨论】:

    标签: spring-integration spring-jdbc spring-el


    【解决方案1】:

    我建议您使用自定义 SqlParameterSourceFactory 并且已经不依赖 SpEL:

    public class CustomSqlParameterSourceFactory implements SqlParameterSourceFactory {
    
        @Override
        public SqlParameterSource createParameterSource(Object input) {
            List<?> objects = (List<?>) input;
            return new BeanPropertySqlParameterSource(objects.get(objects.size() - 1));
        }
    
    }
    

    将此注入JdbcPollingChannelAdapter.setUpdateSqlParameterSourceFactory() 并已在 UPDATE 语句中使用简单属性:

    UPDATE LAST_EVENT_READ SET SEQUENCE=:sequence, EVENT_DATE=:eventDate
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-30
      • 2012-02-22
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 2018-06-09
      相关资源
      最近更新 更多