如何使用spring boot设置速度模板字符编码? [英] How to set velocity template character encoding with spring boot?
问题描述
我的模板使用 UTF-8 作为编码,但我的网络应用程序的输出不正确.问题是速度认为我的模板有 ISO-8859-1 作为编码,因为这是输出:
My templates have UTF-8 as encoding but the output from my web app is not correct. The problem is that velocity think that my templates have ISO-8859-1 as encoding since that is the output from this:
System.out.println(ctx.getBean(VelocityEngine.class).getTemplate("index.html").getEncoding());
可以通过在application.properties中设置spring.velocity.charSet=UTF-8
来配置输出编码,但是我的问题不是输出,是模板编码不对.Velocity 有这个属性 input.encoding
但我不知道如何用 spring boot 以简单的方式设置它.我是否必须将我的模板重新编码为 iso?
It is possible to configure the output encoding by setting spring.velocity.charSet=UTF-8
in application.properties, but my problem is not the output, it is the template encoding that is wrong. Velocity have this property input.encoding
but I can not figure out how to set that with spring boot in an easy way. Do I have to recode my templates to iso?
推荐答案
当在 Spring Boot 中使用模板技术并尝试设置通过默认 Spring Boot 属性(如 spring.velocity.charSet
)不可用的属性时) 有一个 spring.[template-engine].properties.*
可以工作.请参阅属性列表.
When using templating technologies with Spring Boot and trying to set properties not available through default Spring Boot properties (like spring.velocity.charSet
) there is a spring.[template-engine].properties.*
that will work. See the list of properties.
基本上将 spring.velocity.properties.input.encoding=UTF-8
添加到您的 application.properties
应该可以解决问题.
Basically adding spring.velocity.properties.input.encoding=UTF-8
to your application.properties
should do the trick.
spring.velocity.properties.input.encoding=UTF-8
这篇关于如何使用spring boot设置速度模板字符编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!