gpt4 book ai didi

java - mysql查询韩语(外语)单词坏了

转载 作者:行者123 更新时间:2023-11-30 22:56:40 28 4
gpt4 key购买 nike

现在我正在使用 spring 框架 + java + mysql(maria db)执行 select query(for searching) 时,没有问题但是当用韩语 (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”

我以 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

关于java - mysql查询韩语(外语)单词坏了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26075804/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com