【问题标题】:mysql query korean(Foreign language) word is brokenmysql查询韩语(外语)单词坏了
【发布时间】:2014-09-27 14:42:29
【问题描述】:

现在我正在使用 spring 框架 + java + mysql(maria db) 执行选择查询(用于搜索)时,没有问题 但是当用韩语(utf-8)字搜索时 那个词坏了

我认为查询没有问题,因为在搜索英文或数字时 结果很好

这是我的调度器-servlet

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing 
        infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model (annotation true) -->
    <annotation-driven>
        <message-converters>
            <beans:bean
                class="org.springframework.http.converter.StringHttpMessageConverter">
                <beans:property name="supportedMediaTypes" value="text/html;charset=UTF-8" />
            </beans:bean>
        </message-converters>
    </annotation-driven>

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
        up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />
    <resources mapping="/uploadImg/**" location="/uploadImg/" />
    <resources mapping="/UploadFile/**" location="/UploadFile/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->

    <beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <beans:property name="order" value="1"></beans:property>
        <beans:property name="viewClass">
            <beans:value>org.springframework.web.servlet.view.tiles2.TilesView
            </beans:value>
        </beans:property>
    </beans:bean>

    <beans:bean
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <beans:property name="definitions">
            <beans:list>
                <beans:value>/WEB-INF/tiles/tiles-*.xml</beans:value>
            </beans:list>
        </beans:property>
    </beans:bean>


    <context:component-scan base-package="com.ex.biz" />

    <interceptors>
        <beans:bean class="com.ex.biz.intercepter.InterCepterCheck"/>       
    </interceptors>


</beans:beans>

这是 mybatis-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">



    <context:property-placeholder location="classpath:config/ex.properties" />
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${ex_driver}"></property>
        <property name="url" value="${ex_url}"></property>
        <property name="username" value="${ex_username}"></property>
        <property name="password" value="${ex}"></property>
        <property name="validationQuery" value="select 1"></property>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="typeAliasesPackage" value="com.ex.biz.dto"></property>
        <property name="configLocation" value="classpath:config/mybatis.xml"></property>
    </bean>

    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
    </bean>

    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>




</beans>

我应该修改什么配置? 如果我错过了概念,你能告诉我吗? 我现在很困惑……

当我搜索“나나”时,执行的查询写为“ëë”

谢谢你帮助我

【问题讨论】:

  • 您确定数据库表的编码设置为 UTF-8 吗?

标签: java mysql sql spring


【解决方案1】:

我找到了答案 首先我确定我的数据库表设置为“utf-8”

我以 GET 形式发送数据 所以 tomcat 服务器(在 server.xml 中)设置 URIEncoding

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>

URIEncoding="UTF-8"

然后我解决所有问题

如果你有像我这样的问题。 您必须将数据作为 POST 发送。 或者作为 GET 发送,然后将 uriEcoding 放入 server.xml 中

【讨论】:

  • 您可以接受自己的问题。点击检查按钮。
猜你喜欢
  • 1970-01-01
  • 2016-08-30
  • 2012-09-16
  • 1970-01-01
  • 1970-01-01
  • 2013-04-18
  • 2016-11-01
  • 1970-01-01
  • 2012-04-12
相关资源
最近更新 更多