原创文章,转载请注明原文章地址,谢谢!
问题:在做第三方用户登录,对接微信用户登录时,服务器报了如下错误,SQLException:Incorrect string value:'\xF0\X9F\X91\X8C' for column 'real_name' 。
发现是微信用户名保存错误,该微信用户名包含了特殊图标,报错了
image解决方案:
1)在数据库中把对应的字段编码修改为utf8-> utf8mb4
image2)修改application.yml配置文件,在spring.datasource.druid中添加如下配置
connectionInitSqls: "set names utf8mb4"
server:
port: 8000
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/test?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
connectionInitSqls: "set names utf8mb4"
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
test-while-idle: true
test-on-borrow: false
test-on-return: false
stat-view-servlet:
enabled: true
url-pattern: /druid/*
filter:
stat:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
wall:
config:
multi-statement-allow: true
网友评论