现在我正在使用spring framework + 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>
我应该修改什么配置? 如果我错过了概念,你可以让我知道吗? 我现在很困惑......
当我搜索'나나'时执行的查询'''
谢谢你的帮助
答案 0 :(得分:0)
我找到了答案 首先,我确定我的数据库表设置为&#34; utf-8&#34;
我发送数据为GET 所以tomcat服务器(在server.xml中)设置URIEncoding
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
的URIEncoding =&#34; UTF-8&#34;
然后我解决了所有问题
如果你有像我这样的问题。 你必须以POST发送数据。 或者发送为GET,然后将uriEcoding放入server.xml