mysql、mybatis遇到问题集合 使用JDBC连接MySql时出现: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

1、错误描述

之前没有遇到这个错误,现在是mysql的版本是6.几的版本,之前用的5的版本没有出现该问题:

mysql、mybatis遇到问题集合
使用JDBC连接MySql时出现: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

解决方案:

在连接字符串后面加上?serverTimezone=UTC

其中UTC是统一标准世界时间。

完整的连接字符串示例:jdbc:mysql://localhost:3306/test?serverTimezone=UTC

或者还有另一种选择:jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8,这个是解决中文乱码输入问题,当然也可以和上面的一起结合:jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

2、利用springboot集成mybatis的时候发现@Mapper注解不能用,也是因为版本的原因,所以这一块要注意。

3、错误:注解标注在接口还是实现类上面,我将@Service标注在接口上面,结果提示找不到该service类?

@Service注解是标注在接口还是实现类上面?

@Service注解是标注在实现类上的,因为@Service是把spring容器中的bean进行实例化,

也就是等同于new操作,只有实现类是可以进行new实例化的,而接口则不能,所以是加在实现类上的。

一句话:spring容器进行实例化,接口是不能实例化的,只有实现类才可以。

也可以借鉴此博客:

https://blog.csdn.net/qq_35923749/article/details/77159213