Spring Boot与FreeMarker集成后配置全局模板转义html/xml
如果你的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配置项,在
中可以找到
转载于:https://my.oschina.net/buwei/blog/745099