问题
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());
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?
回答1:
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.
Basically adding spring.velocity.properties.input.encoding=UTF-8
to your application.properties
should do the trick.
spring.velocity.properties.input.encoding=UTF-8
来源:https://stackoverflow.com/questions/25836695/how-to-set-velocity-template-character-encoding-with-spring-boot