我失去了我的想法,試圖添加像「ą,ę,ć,ł」等波蘭字符到我的MySQL數據庫。我已經完成的步驟:表格丟失波蘭字符
- 在我的MySQL數據庫中設置「方法比較題注」與
utf8_unicode_ci
。 - 設置爲所有
varchar
領域Method comparing inscription
到utf8_unicode_ci
- 在
application.properties
集:
spring.datasource.url: jdbc:mysql://localhost:3306/database?characterEncoding=UTF-8
spring.mandatory-file-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.datasource.sqlScriptEncoding=UTF-8
- 要確保在所有的HTML文件中添加
<head></head>
括號<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
- 像這樣設置配置文件:
@Configuration
public class Config extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
}
當我嘗試在我的控制器中添加一些波蘭語單詞時,例如player.setName("ĆŁĘ")
- 沒關係。數據庫中的名稱已正確插入。
但是當我從Thymeleaf拿控制器中的玩家name
時,它返回ÄÅÄ
而不是CŁĘ
。我的形式服務員Thymeleaf看起來是這樣的:
<form action="#" th:action="@{/editPlayer}" th:object="${player}" method="post">
<div class="info">Name: </div>
<div class="error" th:if="${#fields.hasErrors('name')}" th:errors="*{name}"/>
<input type="text" th:field="*{name}" placeholder="Name" th:class="${#fields.hasErrors('name')}? 'error'" /><br/>
<input type="button" id="cancel" class="button2 button-cancel" value="CANCEL"/>
<input type="submit" class="button button-submit" value="SUBMIT"/>
</form>
我不知道還有什麼我需要做的,從Thymeleaf得到正確的字符。
歡迎來到Stackoverflow,你的問題並不像你認爲的那樣糟糕。如果Downvoter能夠解釋爲什麼他在得到+2後給這個問題一個-1。 – Ferrybig