如何使用弹簧引导设置速度模板字符编码



我的模板使用UTF-8作为编码,但我的web应用程序的输出不正确。问题是velocity认为我的模板有ISO-8859-1作为编码,因为这是的输出

System.out.println(ctx.getBean(VelocityEngine.class).getTemplate("index.html").getEncoding());

可以通过在application.properties中设置spring.velocity.charSet=UTF-8来配置输出编码,但我的问题不在于输出,而是模板编码错误。Velocity有这个属性input.encoding,但我不知道如何用弹簧引导简单地设置它。我必须将模板重新编码为iso吗?

当在Spring Boot中使用模板技术并试图通过默认的Spring Boot属性(如spring.velocity.charSet)设置不可用的属性时,有一个spring.[template-engine].properties.*可以工作。请参见属性列表。

基本上,将spring.velocity.properties.input.encoding=UTF-8添加到application.properties中就可以了。

spring.velocity.properties.input.encoding=UTF-8

最新更新