Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在数据库中使用hibernate和SpringMVC获取一些utf-8字符?_Java_Spring_Hibernate_Spring Mvc_Tomcat - Fatal编程技术网

Java 如何在数据库中使用hibernate和SpringMVC获取一些utf-8字符?

Java 如何在数据库中使用hibernate和SpringMVC获取一些utf-8字符?,java,spring,hibernate,spring-mvc,tomcat,Java,Spring,Hibernate,Spring Mvc,Tomcat,我开发了小型服务器程序。 当我从数据库中提取元组时,一些字符变成了“ÛÛÃÁ”。 我修改了server.xml。然而,仍然出现了“ÛÛÛÁ”字符。 帮助我。 如何获得正确的字符 这是我的server.xml。(我使用ApacheTomcat7.0服务器。) 首先删除此行 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 这个add-in

我开发了小型服务器程序。 当我从数据库中提取元组时,一些字符变成了“ÛÛÃÁ”。 我修改了server.xml。然而,仍然出现了“ÛÛÛÁ”字符。 帮助我。 如何获得正确的字符

这是我的server.xml。(我使用ApacheTomcat7.0服务器。)


首先删除此行

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

这个add-into头标签

<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />

然后添加到web.xml中

 <filter>
    <filter-name>encoding-filter</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>
 </filter>
 <filter-mapping>
    <filter-name>encoding-filter</filter-name>
    <url-pattern>/*</url-pattern>
 </filter-mapping>

编码过滤器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
编码过滤器
/*
然后将hibernate配置文件添加到

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.connection.CharSet">utf8</prop>
                <prop key="hibernate.connection.characterEncoding">utf8</prop>
                <prop key="hibernate.connection.useUnicode">true</prop>
            </props>
        </property>

org.hibernate.dialogue.mysql5dialogue
真的
更新
utf8
utf8
真的

将characterEncoding=UTF-8追加到数据库连接字符串

    jdbc:mysql://localhost:3306/table_name?useEncoding=true&amp;characterEncoding=UTF-8

哪个数据库引擎?确保您的数据库编码也是UTF-8。。在数据库中,字符是正确的。但是,当我将数据提取到spring服务器时,字符会发生变化。我已经在代码中应用了这些答案。。。在web.xml,pom.xml。我不使用网页。。。我只是用@ResponseBody。所以,我不能添加到标题中。所以,我将您的答案添加到web.xml,servlet-context.xml中。然而,仍然会出现“圣人”的角色。我使用hibernate4。。。。它会在版本4中更改道具?如果您没有使用网页,那么没有问题,但将hibernate配置文件添加到添加此代码会话工厂将对象转换为UTF-8并正确插入。我会在配置文件中插入这些道具。然而也有同样的问题。。。org.hibernate.dialogue.mysqldialogue true更新utf8 utf8 true将表集合更改为utf8\u general\u ci。那么检查工作是否准备好了?谢谢你的回答。。我在上面的答案中找到了一些答案。谢谢你的帮忙。