关于Mybatis出错的一些错误总结

关于mapper.xml中与dao层的参数匹配问题

UserMapper.xml中
在这里插入图片描述
UserDao中
在这里插入图片描述
Test测试中
在这里插入图片描述

userDao中写的方法如果不指定名字将会报一下错误 绑定异常
eg:
org.apache.ibatis.binding.BindingException: Parameter ‘username’ not found.

在这里插入图片描述

怎样解决呢?

正确写法:
第一种:
UserDao中加入@param表示把该参数的名称作为映射文件的参数名
在这里插入图片描述
UserMapper.xml中:
在这里插入图片描述
第二种:
UserMapper.xml中:
在这里插入图片描述
UserDao中
在这里插入图片描述

关于以下错误的分析

1.查找的id不存在
2.没有把映射文件放入到配置文件中
在这里插入图片描述

没有把映射文件放入到配置文件中

会报一下错误:
在这里插入图片描述
mapper中的xml
在这里插入图片描述

参数类型匹配不上

常见错误:
Cause: java.lang.IllegalArgumentException: argument type mismatch
在这里插入图片描述
如下图是正确的:
在这里插入图片描述

时区问题:

表示db.properties中时区没有加:serverTimezone=UTC
在这里插入图片描述
错误代码:Cause: 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.

猜你喜欢

转载自blog.csdn.net/weixin_45861581/article/details/115069699