Spring MVC显示Unicode字符不正确

时间:2017-05-04 12:10:31

标签: java mysql spring spring-mvc unicode

我有一个Web应用程序使用Spring MVC,版本4.3.8.RELEASE。它保存Unicode字符不正确:

enter image description here

我查了很多观点:

(1)在MySQL数据库中,它是NVARCHAR,而不是VARCHAR

(2)在pom.xml中,我添加了

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

(3)在JSP页面中,我添加

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> 

(4)在web.xml内,我添加了

<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

(5)在bean控制消息中,我添加

<beans:bean id="messageSource"
            class="org.springframework.context.support.ResourceBundleMessageSource">
    <beans:property name="basename" value="META-INF/messages/messages"/>
    <beans:property name="defaultEncoding" value="UTF-8"/>
</beans:bean>

(6)在ViewResolver中,我还为UTF-8添加了属性 ...

但不成功。如何解决?

这是我的项目:https://github.com/donhuvy/temp_unicode

1 个答案:

答案 0 :(得分:0)

问号告诉我(在这种情况下)数据在插入表格时被破坏了。也就是说,越南人物丢失了。

现在,要弄清楚要做什么。转到Trouble with utf8 characters; what I see is not what I stored

  • 阅读“最佳实践”;它可能会指出做错了什么。
  • 了解“问号”;它提供了问题的可能原因。
  • SELECT HEX(...)...; Điện lạnh,如果正确存储(到utf8或utf8mb4),则为C490 69 E1BB87 6E 20 6C E1BAA1 6E 68

在您的评论中Ä?iá»?n lạnh - 是从桌子中取出后的吗?如果是这样,那就太晚了。