120.2. URI 格式
注意
此组件可用作 事务客户端。
SQL 组件使用以下端点 URI 表示法:
sql:select * from table where id=# order by name[?options]
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]
sql:select * from table where id=:#myId order by name[?options]
使用命名参数时,Camel 将在给定优先级中查找名称:
-
来自消息正文(如果其
java.util.Map) - 来自消息标头
如果无法解析命名参数,则会抛出异常。
您可以使用简单表达式作为参数,如下所示:
sql:select * from table where id=:#${exchangeProperty.myId} order by name[?options]
sql:select * from table where id=:#${exchangeProperty.myId} order by name[?options]
请注意,标准 ? 符号表示 SQL 查询的参数被替换为 # 符号,因为 ? 符号用于指定端点的选项。可以基于端点配置 ? 符号替换。
您可以将 SQL 查询外部化到类路径或文件系统中的文件,如下所示:
sql:classpath:sql/myquery.sql[?options]
sql:classpath:sql/myquery.sql[?options]
myquery.sql 文件位于 classpath 中,只是一个纯文本
在 文件中,您可以根据需要使用多行并格式化 SQL。和 也可使用 - dash 行等注释。