315.3. 샘플

315.3.1. 표현식 템플릿

표현식 템플릿(Templating)이 활성화되기 때문에 SPEL 표현식이 #{ } 구분 기호로 둘러싸여 있어야 합니다. 이를 통해 SpEL 표현식을 정규 텍스트와 결합하고 이를 매우 가벼운 템플릿 언어로 사용할 수 있습니다.

예를 들어 다음 경로를 구성하는 경우:

from("direct:example")
    .setBody(spel("Hello #{request.body}! What a beautiful #{request.headers['dayOrNight']}"))
    .to("mock:result");

위의 경로에서 notice spel은 org.apache.camel.language.spel.spel.spel.spel.spel.spel 에서 가져와야 하는 정적 메서드이며 매개 변수를 매개 변수로 매개 변수로 매개 변수로 매개 변수를 사용하여 setBody 메서드에 전달합니다. 그러나 fluent API를 사용하는 경우 대신 이 작업을 수행할 수 있습니다.

from("direct:example")
    .setBody().spel("Hello #{request.body}! What a beautiful #{request.headers['dayOrNight']}")
    .to("mock:result");

이제 setBody() 메서드의 spel 메서드를 사용합니다. 그리고 이것은 우리가 org.apache.camel.language.spel.SpelExpression.spel.spel.spel.spel.spel .spel에서 spel 메서드를 정적으로 가져올 필요가 없습니다.

및 본문에 "World" 문자열과 "dayOrNight"라는 헤더와 "day" 값으로 메시지를 전송했습니다.

template.sendBodyAndHeader("direct:example", "World", "dayOrNight", "day");

mock:result 의 출력은 "Hello World! 좋은 날이란 무엇입니까?