137.2. URI 格式
注意
此组件可用作 事务客户端。
SQL 组件使用以下端点 URI 表示法:
sql:select * from table where id=# order by name[?options]
您可以使用 :'#name_of_the_parameter' 风格来使用命名的参数,如下所示:
sql:select * from table where id=:#myId order by name[?options]
使用命名参数时,Camel 将按照给定优先级从中查找名称:
-
如果它是一个
java.util.Map - 来自消息标头
如果无法解析指定参数,则抛出异常。
您可以使用 Simple 表达式作为参数,如下所示:
sql:select * from table where id=:#${exchangeProperty.myId} order by name[?options]
请注意,表示 SQL 查询参数的标准 ? 符号被 @ 符号替换,因为 ? 符号用于指定端点的选项。? 符号替换可根据端点进行配置。
您可以将 SQL 查询外部化到 classpath 或文件系统中的文件,如下所示:
sql:classpath:sql/myquery.sql[?options]
myquery.sql 文件位于 classpath 中,且只是纯文本
-- this is a comment
select *
from table
where
id = :#${exchangeProperty.myId}
order by
name
在文件中,您可以根据需要使用多行并格式化 SQL。和 也会使用诸如 - dash 行等注释。