Hibernate與MySQL開發中亂碼解決方案
本文參考自:http://blog.tremend.ro/2007/08/14/how-to-set-the-default-charset-to-utf-8-for-create-table-when-using-hibernate-with-java-persistence-annotations/,感謝提供者spostelnicu.
問題:hibernate與mysql開發中,新增和修改時出現中文亂碼
解決:
步驟一:將hibernate.cfg.xml中的connection.url值加入characterEncoding=utf8,具體如下:
文件:hibernate.cfg.xml內容
之後,將hibernate的方言映身到該文件:
文件: hibernate.cfg.xml<!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory>...<property name="hibernate.connection.charSet">utf8(或utf-8)</property>... <session-factory><hibernate-configuration>
小弟只是略懂皮毛,拋磚引玉,希望高手們能提供更好的解決方案,如有不足之處,還請高手們留言提點....多謝...