What is the best way to ensure HTML entities are escaped in StringTemplate

后端 未结 2 1552
面向向阳花
面向向阳花 2021-01-07 06:07

Assuming the following string template, is being given a list of Java Bean objects:

    $people:{p|
  • $p.name$ $p.email
  • }$
2条回答
  •  温柔的废话
    2021-01-07 06:59

    It's not necessary to write your own renderer for this. You may use the builtin renderer org.stringtemplate.v4.StringRenderer

    group.registerRenderer(String.class, new StringRenderer());
    

    and add in your template :

      $people:{p|
    • $p.name;format="xml-encode"$ $p.email;format="xml-encode"$
    • }$

提交回复
热议问题