【发布时间】:2014-08-31 11:14:42
【问题描述】:
我如何“说”Spring Boot 使用 UTF-8 编码,正确显示和保存德语变音符号? 我们正在使用 Sping-Boot 1.1.1 (Release) 编写 Java-Web 应用程序,并使用 TomCat7 或 Jetty 作为网络服务器。数据库为postgresql或h2,用于测试。
编辑:
我用属性文件试了一下(感谢回答),但没有可见的变化。
数据库也是 UTF-8... 尤其是当我们向 Web 服务器发送 POST-Request 时,问题就来了。 Spring-Request-Handler 已经获得了损坏的编码值。 在下面您可以看到部分代码: (它显示了 Thymeleaf-Template 的 sn-p)
<form accept-charset="utf-8" method="post">
<div class="row">
<fieldset th:object="${model}">
<!-- CSRF token -->
<th:block th:replace="makros :: csrf" />
<div class="col-sm-4 form-group" >
<label for="firstname" th:text="#{edit_user.first_name}">Given Name</label>
<input class="form-control required" type="text" required="required" id="firstname" name="firstname" th:field="*{firstName}" />
</div>
<div class="col-sm-4 form-group">
<label for="firstname" th:text="#{edit_user.last_name}">Family Name</label>
<input class="form-control required" type="text" required="required" id="lastname" name="lastname" th:field="*{lastName}" />
</div>
</fieldset>
</div>
</form>
这是它的请求处理程序:
@RequestMapping(method = RequestMethod.POST)
public String handleUserUpdate(@ModelAttribute(MODEL) UpdateUserCommand command) {
//here we cut the broken encoded values
}
问候 史蒂夫
【问题讨论】:
标签: utf-8 character-encoding spring-boot