【问题标题】:BeanPropertySqlParameterSource to insert list of valuesBeanPropertySqlParameterSource 插入值列表
【发布时间】:2014-11-10 10:02:40
【问题描述】:

如果 bean 有列表字段,我如何使用 NamedParameterJdbcTemplate 使用 BeanPropertySqlParameterSource 将值列表插入数据库?如果不可能,那我应该使用什么?

【问题讨论】:

    标签: java spring


    【解决方案1】:

    没有直接的方法,因为没有直接的方法将值列表映射到一列。您可能希望它做很多事情。这是最接近的选择。

    How to generate a dynamic "in (...)" sql list through Spring JdbcTemplate?

    String query = "select * from table where columnName in (:listOfValues)"; List nameRecordIDs = new ArrayList(); // ... // add values to collection, then // ... Map namedParameters = Collections.singletonMap("listOfValues", nameRecordIDs); namedparameterJdbcTemplate.query(query, namedParameters,new MyMapper());

    【讨论】:

      猜你喜欢
      • 2014-05-13
      • 2011-12-04
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      相关资源
      最近更新 更多