如果你的FreeMarker版本大于等于 2.3.24,在与spring boot集成后,有两种方式配置自动转义为HTML或者XML。

方式一:

在spring boot的配置文件中设置:

spring.freemarker.suffix=.ftlh
spring.freemarker.settings.recognize_standard_file_extensions=true

spring.freemarker.settings.recognize_standard_file_extensions=true这项必须为true,如果不设置,转义是不生效的,

配置suffix为ftlh时,会自动进行html escape;

配置suffix为ftlx时,会自动进行xml escape;

可以在模板页面中输出${" ' "}${"<"}观察效果。

方式二:

配置文件中设置:

# for example HTMLOutputFormat or XMLOutputFormat.
spring.freemarker.settings.output_format=HTMLOutputFormat 

这种方式只需要用常规的 ftl 后缀名也能生效。

 

说明: 常规的 spring.freemarker.settings.* 有哪些可设置的FreeMarker配置项,在

http://freemarker.org/docs/api/freemarker/template/Configuration.html#setSetting-java.lang.String-java.lang.String-

中可以找到

Spring Boot与FreeMarker集成后配置全局模板转义html/xml

转载于:https://my.oschina.net/buwei/blog/745099

相关文章:

  • 2021-12-22
  • 2021-10-08
  • 2021-08-18
  • 2022-12-23
  • 2021-08-15
  • 2021-05-28
  • 2021-07-06
  • 2021-12-20
猜你喜欢
  • 2021-05-19
  • 2022-12-23
  • 2021-08-31
  • 2021-05-15
  • 2021-07-14
  • 2022-12-23
  • 2021-12-13
相关资源
相似解决方案