现在的位置: 首页 > 综合 > 正文

Hibernate – 中文乱码

2019年08月28日 ⁄ 综合 ⁄ 共 284字 ⁄ 字号 评论关闭

在 database 和 table 都是 utf8 编码的前提下,

在 hibernate.cfg.xml 的 <session-factory> 结点中加入

<property name="connection.characterEncoding">utf8</property>

若整合了 Spring 和 Hibernate,在 applicationContext.xml 中的指定 datasource 的 bean 结点中这样做:

<property name="jdbcUrl" value="jdbc:mysql://localhost/dbname?characterEncoding=utf8"/>

抱歉!评论已关闭.