如何使用Spring JDBCTemplate绑定元组列表? [英] how to bind a list of tuples using Spring JDBCTemplate?
本文介绍了如何使用Spring JDBCTemplate绑定元组列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的查询:
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查询发送到数据库:
This will send this SQL query to the database:
select * from bla where id in ( 1, 2, 3 )
现在,我要将这种类型的查询发送到数据库:
Now I want to send this type of query to the database:
select * from bla where (id,name) in ( (1,'foo'), (2,'bar'), (3,'foobar'))
我是否需要传递List< List< Object>>要做到这一点?它可以与Spring JDBCTemplate一起使用吗?
Do I need to pass a List<List<Object>> to accomplish this? Will it work with Spring JDBCTemplate?
推荐答案
我调试了Spring代码,发现它希望将元组作为Object []提供,因此要与List一起使用,它应该是List<对象[]>.
I have debugged Spring code and found that it expects tuples to be provided as Object[], so for it to work with a List it should be a List<Object[]>.
这篇关于如何使用Spring JDBCTemplate绑定元组列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文