61.13. 동적 값이 포함된 IN 쿼리 사용
SQL 생산자를 사용하면 IN 값이 동적 계산되는 IN 문과 함께 SQL 쿼리를 사용할 수 있습니다. 예를 들어 메시지 본문 또는 헤더 등의 경우For example from the message body or a header etc.
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");