Java 弹簧数据';s save方法会导致丢失一些数据
我使用的是SpringBoot+SpringDataJPA+PostgreSQL。我有一个包含一些字符串的简单类 例如:Java 弹簧数据';s save方法会导致丢失一些数据,java,spring,spring-boot,spring-data,spring-data-jpa,Java,Spring,Spring Boot,Spring Data,Spring Data Jpa,我使用的是SpringBoot+SpringDataJPA+PostgreSQL。我有一个包含一些字符串的简单类 例如: public class Person { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; private String surname; } 我正在创造新的人: Person person = new
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String surname;
}
我正在创造新的人:
Person person = new Person(null, "Roman", "Brzęścikiewicz");
其中包含一些波兰符号,如“ę”和“ś”。
当我将其保存到数据库时:
personRepository.save(person);
id;name;surname
1;Roman;Brzescikiewicz
然后,我留下了保存在数据库中的人员,该人员收到了ID和姓名,但没有姓氏示例:
id;name;surname
1;Roman;
但当我的姓氏没有波兰符号时,我在数据库中得到了正确的行:
personRepository.save(person);
id;name;surname
1;Roman;Brzescikiewicz
我的应用程序属性:
spring.datasource.url=jdbc:postgresql://localhost:5433/db
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=validate
添加
?useUnicode=true&characterEncoding=utf8
正如一些Qestion上所建议的,stackoverflow将不起作用
有什么想法吗 字符表编码错误。UTF-8!=utf8
characterEncoding=UTF-8
将其添加到您的jdbc URL中
jdbc:postgresql://localhost:5433/db?useUnicode=yes&characterEncoding=UTF-8
您可以阅读相同情况的示例
实际上,这是一个非常愚蠢的问题。我使用PhpPgAdmin在数据库中搜索,PhpPgAdmin有一个错误,没有显示波兰符号。。。在pgadmin4中,它正确显示,如果我通过rest控制器中的spring JPA访问数据,它也可以正常工作。数据库和表编码方案如何?将其添加到ma jdbc url并尝试:characterEncoding=UTF-8 spring.JPA.characterEncoding=UTF-8 spring.JPA.hibernate.characterEncoding=UTF-8 spring.datasource.characterEncoding=UTF-8 springhibernate.characterEncoding=UTF-8,仍然不工作。您可以检查您的数据库模式编码是否也是UTF-8吗?您可以将某些DB客户端连接到您的DB,并检查propertyserver编码是否为utf8,数据库编码是否为utf8,排序规则是否为en_US.utf8,字符类型是否相同。当我通过SQL插入带有波兰符号的姓氏时,它可以工作,但不能与spring数据一起工作。您可以在此处复制spring.datasource.url属性的值吗?