51.13. 使用带有动态值的 IN 查询
SQL 制作者允许在计算 IN 值的 IN 语句中使用 SQL 查询。例如,来自邮件正文或标头等。
要使用 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");