java 对象显示正常。但在 MySQL Query Browser 中看到的是乱码,传给前端的 Flex 也是乱码。
原因: Hibernate 的基础还是 JDBC ,所以一样需要设置 characterEncoding !
在 hibernate.cfg.xml 中应该这样写
<property name="connection.url">jdbc:mysql://localhost:3306/test?useUnic ode=true&characterEncoding=UTF-8</property>
如果用 hibernate.properties
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UT-F8
ps :处理中文的话, characterEncoding 用 GBK 一样可以。
我的项目是:
<property
name="connection.url">jdbc:mysql://localhost:3306/myeshop?useUnicode=tru
e&characterEncoding=UTF-8</property>
2. 同样在 spring 里的 applicationContext.xml 里的数据库连接也要修改:
<property name="url"
value="jdbc:mysql://localhost:3306/myeshop?useUnicode=true&character
3. 在 Web.xml 中配置 encodingFilter 过滤器 , 在 web.xml 中加入下面代码
<filter>
<filter-class>
<init-param>
<param-value>UTF-8</param-value>
</init-param>
<filter-mapping>
SSH 下 mysql 中文乱码问题
标签:
mysql 中文乱码
分类:
mysql
2010-08-25 11:05
1. 在 hibernate.cfg.xml 配置文件中修改如下
环境:Hibernate 3.2 + MySQL5.0(MySQL 的编码已设置为 utf8)
问题:通过 Hibernate 向 MySQL 写入中文后,通过 Hibernate 取回数据,在 console 中打
印
解决方法:
#hibernate.connection.url
但字节编码问题最好的解决方法还是统一使用 UTF-8
Encoding=UTF-8"></property>
<filter-name>encodingFilter</filter-name>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<param-name>encoding</param-name>
</filter>
<filter-name>encodingFilter</filter-name>
评论0
最新资源