如何添加注释

  1. <! 这是注释 !>

如何忽略前后空白

  1. <if(!map.alarmTypeIsDown)> ${
  2. N}<if(map.legoLogo)>![logo image](<map.legoLogo>)<endif>${
  3. N}<map.fullMsg>
  4. <else>${
  5. N} <if(map.legoLogo)>![logo image](<map.legoLogo>)<endif>
  6. <if(map.dingChartUrl)>![alarm image](<map.dingChartUrl>)<endif> ${
  7. N}**告警简述**:<if(map.pLevel)><map.pLevel>,<endif><if(map.sLevel)><map.sLevel>,<endif><map.alertTime>,[<map.pName>][<map.bpName>.<map.dimCombineName>.<map.quotaName>],<map.fallRange>分钟累计跌幅<map.fallPer>.
  8. <if(map.bpNames)> **告警关联**:[<map.bpNames;separator=",">]<endif>
  9. <if(map.decision)> **决策结果**:[<map.decision>]<endif>
  10. <endif>

如何使用函数将模板管理的更加方便

  1. https://github.com/antlr/stringtemplate4/blob/master/doc/cheatsheet.md#functions

image.png

如何将参数在子模板中一路透传

子函数内的内容自动缩进

  1. STGroup stGroup = new STGroup();
  2. stGroup.defineTemplate("main", "", "\n" + "{\n" + " \t<childStatement()>\n" + "}\n" + "");
  3. stGroup.defineTemplate("childStatement", "", "select <columns;separator=\",\">\n" + "from table\n"
  4. + "where 1=1 <if(condition)>and <condition><endif>");
  5. System.out.println(stGroup.getInstanceOf("main").render());