按照以往經驗逐個排查,開發環境統一爲utf-8編碼,服務器也配置了編碼過濾器,tomcat也是utf-8編碼。前臺頁面也是utf-8編碼的。html
鬱悶,到底哪裏出錯了呢?java
排錯1:開發者工具檢查請求,發現個人post請求體(表單)亂碼(回過頭來看,其實仍是thymeleaf配置出錯引起的)spring
排錯2:感受服務器應該沒問題了,但是頁面怎麼仍是亂碼?tomcat
百度查有人說多是文件編碼不對,即文件編碼不是頁面中設置的utf-8,因而仔細檢查另存一下,發現依舊亂碼 ==|
服務器
排錯3:既然前臺html沒問題,服務器也沒問題,那麼天然而然的懷疑到了thymeleaf身上了工具
1:模板解析器設置編碼utf-8post
1 @Bean 2 public ITemplateResolver templateResolver() { 3 ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); 4 templateResolver.setPrefix("/WEB-INF/templates/"); 5 templateResolver.setSuffix(".html"); 6 templateResolver.setTemplateMode("HTML5"); 7 templateResolver.setCharacterEncoding("utf-8"); 8 templateResolver.setCacheable(false); 9 return templateResolver; 10 }
2:視圖解析器設置編碼utf-8編碼
1 @Bean 2 public ViewResolver springThymeleafViewResolver() { 3 4 ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); 5 viewResolver.setTemplateEngine(templateEngine()); 6 viewResolver.setOrder(1); 7 viewResolver.setCharacterEncoding("utf-8"); 8 return viewResolver; 9 }
OK,解決問題。spa