标签:
按照以往经验逐个排查,开发环境统一为utf-8编码,服务器也配置了编码过滤器。前台页面也是utf编码的。
郁闷,到底哪里出错了呢?
排错1:开发者工具检查请求,发现我的post请求体(表单)乱码
排错2:服务器应该没问题,可是页面怎么还是乱码?
百度查有人说可能可能是文件编码不对,即文件编码不是页面中设置的utf-8,于是仔细检查另存一下,发现依旧乱码 ==|
1:模板解析器设置编码utf-8
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,解决问题。
SpringMvc+thymeleaf+HTML5中文乱码问题
标签:
原文地址:http://www.cnblogs.com/peak-c/p/4890150.html