How to set velocity template character encoding with spring boot?

和自甴很熟 提交于 2019-12-07 18:21:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!