具体报错如下:
java.sql.SQLException: The server time zone value ‘�й���ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
报错信息很明白,你需要配置一个时区.
我原来的jdbc:
spring.datasource.url=jdbc:mysql://localhost:3306/test?
我加上时区后的jdbc和编码格式的jdbc:
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&characterEncoding=utf8
查询成功:

题外话说一句:

- 如果使用spring.datasource.driver-class-name=com.mysql.jdbc.Driver过时,可以使用spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
- mybatis.configuration.map-underscore-to-camel-case=true 意思是把数据库里面的下划线格式book_name,映射成bookName这种驼峰格式.名称很清楚map(转换,映射),underscore(下划线),camel(骆驼).
本文详细解释了如何解决在连接MySQL数据库时遇到的时区配置错误,通过正确设置URL参数serverTimezone来指定时区,同时介绍了如何更新过时的Driver类名以及MyBatis中下划线转驼峰的配置。
706

被折叠的 条评论
为什么被折叠?



