如何使用Spring JDBCTemplate绑定元组列表?

13

我有一些类似这样的查询:

List listOfIntegers = Arrays.asList(new Integer[] {1, 2, 3});
List objects = 
    namedParameterJdbcTemplate.query("select * from bla where id in ( :ids )",
            Collections.singletonMap("ids", listOfIntegers),
            myRowMapper);

这会将此SQL查询发送到数据库:
select * from bla where id in ( 1, 2, 3 )

现在我想将这种类型的查询发送到数据库中:

select * from bla where (id,name) in ( (1,'foo'), (2,'bar'), (3,'foobar'))

我需要传递一个 List<List<Object>> 吗?这个方法在 Spring JDBCTemplate 中可以使用吗?


测试了List<List<Object>>,但是没有成功。调试处理整数列表的Spring代码时,我发现它为列表中的每个元素生成一系列“?”。 - Constantino Cronemberger
1个回答

18

我已经调试了Spring代码,并发现它期望以Object[]的形式提供元组,因此为了让它能够与List一起使用,应该将其作为List<Object[]>。


你好,能否看一下这个问题:https://stackoverflow.com/questions/55877193/spring-jpa-repository-jpql-query-using-a-collection-of-objects - andresscode
对我来说,这个不起作用 :( - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接