Flow ServerStarter
数据读写

模板渲染

type template

在设计器中打开 ↗

用 Freemarker 渲染模板

使用说明

要点:用 Freemarker 渲染模板,resourceUri 形如 classpath:templates/hello.ftl。示例先把 JSON 请求体转成 Map 作为数据模型。
可选依赖该节点需要宿主额外引入 camel-freemarker-starter,否则部署相关流程会在 Camel 启动路由阶段失败并回滚。

属性

字段类型必填默认值说明
resourceUri
模板资源
文本 必填 — classpath:templates/hello.ftl

示例流程

可直接保存为 demo-template.json 并部署;非入口节点默认套了一个 REST 入口。

Flow JSON
{
  "id": "demo-template",
  "desc": "模板渲染 示例",
  "group": "示例/数据读写",
  "schemaVersion": 1,
  "nodes": [
    {
      "id": "n1",
      "type": "rest",
      "props": {
        "method": "POST",
        "path": "/demo/template",
        "desc": "示例入口"
      }
    },
    {
      "type": "unmarshal",
      "props": {
        "format": "json",
        "type": "java.util.Map"
      },
      "id": "n1"
    },
    {
      "type": "template",
      "props": {
        "resourceUri": "classpath:templates/hello.ftl"
      },
      "id": "n2"
    }
  ]
}
部署这段流程
curl -X POST 'http://localhost:8086/flow' \
  -H 'Content-Type: application/json' \
  -H 'X-Flow-Token: change-me' \
  --data-binary @demo-template.json

调用方式

如何触发:需要把模板文件放到宿主 classpath:templates/ 下;消息体作为 Freemarker 数据模型。

相关节点