【发布时间】: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 吗?