326.12. 使用带有动态值的 IN 查询
从 Camel 2.17 开始提供
从 SQL 生成者上的 Camel 2.17 中,可以将 SQL 查询与 IN 值动态计算的 IN 语句一起使用。例如,来自消息正文或标头等。
要使用 IN,您需要:
-
使用以下内容为参数名称
加上前缀: -
在参数外添加
( )
一个示例解释了这一点。使用以下查询:
-- this is a comment select * from projects where project in (:#in:names) order by id
-- this is a comment
select *
from projects
where project in (:#in:names)
order by id
在以下路由中:
from("direct:query")
.to("sql:classpath:sql/selectProjectsIn.sql")
.to("log:query")
.to("mock:query");
from("direct:query")
.to("sql:classpath:sql/selectProjectsIn.sql")
.to("log:query")
.to("mock:query");
然后,IN 查询可以使用键名称的标头以及动态值,例如:
查询也可以在端点中指定,而不是外部化(代表外部大小使维护 SQL 查询变得更加容易)
from("direct:query")
.to("sql:select * from projects where project in (:#in:names) order by id")
.to("log:query")
.to("mock:query");
from("direct:query")
.to("sql:select * from projects where project in (:#in:names) order by id")
.to("log:query")
.to("mock:query");