用springboot、mysql,在页面添加或修改对象,保存到数据库,出现乱码。有几种可能的原因:
- 页面的字符编码采用utf-8
- 数据库、表、字段都要采用utf-8
- application.yml也要注意字符集,尤其是jdbc的url参数要加上utf-8
server:
port: 80
servlet:
context-path: /
tomcat:
uri-encoding: UTF-8
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?autoReconnect=true&initialTimeout=3&useUnicode=true&characterEncoding=utf-8
username: root
password: hanming123
jpa:
hibernate:
ddl-auto: update
show-sql: true
http:
encoding:
force: true
charset: UTF-8
enabled: true