1、Field userMapper in com.example.activitdemo.serviceImpl.UserServiceInpl required a bean of type 'com.example.activitdemo.dao.UserMapper' that could not be found.
在启动类 XXXXApplication 上加上注解 @MapperScan("com.example.activitdemo.dao"),或在mapper类上加上 @Mapper()
2、org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxxController' ..... Cause: org.apache.ibatis.builder.BuilderException: Mapper's namespace cannot be empty
xxxMapper.xml中没有指定namespace 在<mapper>标签中加上 namespace="xx.xx.xx.xx.UserMapper"
3、Parameter 'userid' not found. Available parameters are [arg1, arg0, param1, param2]
这样写 X:
public interface UserMapper {
TBEmp1 getUser(String name, String password);
}
这样写 √: 注意导入的包
import org.apache.ibatis.annotations.Param;
public interface UserMapper {
TBEmp1 getUser(@Param("name") String name,@Param("password") String password);
}
4、确定好mysql的版本再引入依赖和配置数据库链接驱动,确定mysql服务开启了再测试连接
mysql 5.0版本 :
<!--MySQL数据库配置--> #数据库链接驱动
<dependency> driver-class-name: com.mysql.jdbc.Driver
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
<scope>runtime</scope>
</dependency>
mysql 8.0 版本:
<!--MySQL数据库配置--> #数据库连接驱动 <dependency> driver-class-name: com.mysql.cj.jdbc.Driver <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.15</version> </dependency>
#url 粘贴复制记得修改成自己的ip、端口和数据库 当我花一小时查出来是这个问题时死的心都有了 url: jdbc:mysql://192.168.206.220:3306/activiti?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT mysql8.0版本的url完全版
url: jdbc:mysql://192.168.206.220:3306/activiti?serverTimezone=UTC mysql8.0版本的url简洁版
url: jdbc:mysql://192.168.206.220:3306/activiti mysql5.0版本
以上三部分无误可以避免以下问题:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure;
com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the ...
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'xxx' is unrecognized or represents more than one time zone