问题:通过Hibernate向MySQL写入中文后,通过Hibernate取回数据,在console中打印java对象显示正常。但在MySQL Query Browser中看到的是乱码,传给前端的Flex也是乱码。
原因:Hibernate的基础还是JDBC,所以一样需要设置characterEncoding!
解决方法
在hibernate.cfg.xml中应该这样写
<property name="connection.url">jdbc:mysql://localhost:3306/yidishui?useUnicode=true&amp;characterEncoding=UTF-8</property>
如果用hibernate.properties
#hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8

ps:处理中文的话,characterEncoding用GBK一样可以。
但字节编码问题最好的解决方法还是统一使用UTF-8!!!

相关文章:

  • 2022-01-04
  • 2021-08-20
  • 2021-04-28
  • 2022-12-23
  • 2021-11-12
猜你喜欢
  • 2021-09-16
  • 2022-02-22
  • 2021-08-25
  • 2022-02-03
  • 2021-11-06
  • 2021-05-25
相关资源
相似解决方案