最新线上出现一个bug,原因是客户输入了特殊汉字导致的
福永街道文𧚔大厦2座6B
如果不做任何处理,项目会抛异常,如下:
java.sql.SQLException: Incorrect string value: '\xF0\xA7\x9A\x94\xE5\xA4...' for column 'remark' at row 1
; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect string value: '\xF0\xA7\x9A\x94\xE5\xA4...'
如果抛这个异常:我们可以将字段的类型修改为“text”,接下来,运行,发现还是有问题:
org.springframework.jdbc.UncategorizedSQLException:
### Error updating database. Cause: java.sql.SQLException: Incorrect string value: '\xF0\xA7\x9A\x94\xE5\xA4...' for column 'remark' at row 1
这是,我们只需要将字段的字符格式修改为:utf8mb4 问题就解决了。emoji表情图同理