JPA+Mysql存储数据乱码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wanghantong/article/details/46055789

JPA+Mysql开发过程中存储数据,遇到中文乱码:

IDE : Eclipse

Project Encoding : UTF-8

Mysql Encoding :UTF-8

Table Encoding:DEFAULT CHARSET utf8


执行代码对数据进行保存后,查询数据库发现中文乱码


解决方案:

persistence.xml中配置数据库名称的时候,在数据库名后指定参数,控制编码

例:

<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/shopping?characterEncoding=utf-8" />



猜你喜欢

转载自blog.csdn.net/wanghantong/article/details/46055789