postgresql - 使用 data.sql 文件初始化 postgreSQL db 并进行 utf-8 编码工作
问题描述
当使用 data.sql 文件通过 application.properties 初始化 postgreSQL 数据库时,插入的带有需要 utf-8 编码的字符(如 Ä 和 ö)的数据不会在各自的字段中正确编码。
所以,我在 application.properties 文件中有以下内容来填充数据库......
spring.datasource.initialization-mode=always
spring.datasource.data=classpath:data.sql
...
Spring 通过以下方式创建模式:
spring.jpa.hibernate.ddl-auto=create-drop
我还应该定义什么来让这些字符正确编码 utf-8。
此外,在 pgAdmin 属性中,我可以看到数据库本身是 utf-8 编码的。
解决方案
我从另一个线程中找到了答案:Spring and PostgreSQL 之间的错误编码。
这只是在应用程序属性中所需要的,而 utf-8 编码现在可以工作:
spring.datasource.sql-script-encoding= UTF-8
推荐阅读
- node.js - 在nest js中管理上传的图像
- java - 在 Java 中从文本文件中查找短语
- javascript - 从 NPM Gulp 安装
- sql-server - 尝试在多个查询上使用 UNION 但由于我的子查询使用 AVG 而无法工作
- python - 从“lambda”函数传递
- tfs - 无法在 Gated Check-in 上协调工作区
- php - 为 Woocommerce 产品单页创建带有图片上传的表单
- google-analytics - 通过 Google Analytics API 和 GA Web UI 获取的数据不匹配
- javascript - 我的反应应用在数字海洋上部署后不显示任何内容
- java - 如果单词完全大写,如何在保持单词大写的同时将第一个字母大写并小写其余字母 - java