具体报错如下:
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(骆驼).