Spring-Boot,无法使用spring-data JPA在MySql中保存unicode字符串
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Spring-Boot,无法使用spring-data JPA在MySql中保存unicode字符串,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1449字,纯文字阅读大概需要3分钟。
内容图文
![Spring-Boot,无法使用spring-data JPA在MySql中保存unicode字符串](/upload/InfoBanner/zyjiaocheng/909/8a2e2899ab01418c8e716af7bfbd6b8a.jpg)
我有我的application.properties设置如下:
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.url = jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
在我的pom.xml中,我的属性设置如下:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<start-class>toyanathapi.Application</start-class>
<java.version>1.8</java.version>
</properties>
我的实体:
@实体
公共类DailyRashifalEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String date;
private int rollno;
private String name;
//Constructors and getters/setters
}
问题1:如果我使用上面的设置,我会得到异常
java.sql.SQLException: Incorrect string value: '\xE0\xA4\xA7\xE0\xA4\xBE...
问题2:如果我将数据源URL更改为:
spring.datasource.url = jdbc:mysql://localhost:3306/dbname
我的数据库中的unicodes会像这样保存
29 | 2074-03-04 | 3 | ?????????????? ?????,?????? ??????, ??????????? ????? ? ???? ???? ???? ??????
如何将它们保存在Mysql中,就像它们在unicode中而不是将所有unicode数据转换为???????? .
解决方法:
在/etc/mysql/my.cnf文件中更改以下内容.
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
内容总结
以上是互联网集市为您收集整理的Spring-Boot,无法使用spring-data JPA在MySql中保存unicode字符串全部内容,希望文章能够帮你解决Spring-Boot,无法使用spring-data JPA在MySql中保存unicode字符串所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。