第一点:绑定异常
org.apache.ibatis.binding.BindingException: Type interface com.dao.UserDao is not known to the MapperRegistry
这问题主要是没有注册Mapper
<mappers>
<mapper resource="com/dao/UserMapper.xml"/>
</mappers>
第二个、org.apache.ibatis.exceptions.PersistenceException:
Error building SqlSession
第三个
Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc.Driver
这是没这个驱动
只要在这个位置上
com.mysql.jdbc.Driver
第四、
找不到数据库
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database **'mybatis'**
这个改为自己的数据库名就可以
第五 ause: java.io.IOException: Could not find resource com/dao/UserMapper.xml
这个是找不到这个UserMapper.xml
第六
Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效。
总结
IDEA工具下,mybatis访问数据库时要注意一下事项
1、在主配置中地址要用"/"如:com/dao/UserMapper.xml
2、在mapper配置文件namespace的地址要用点如:namespace="com.dao.UserDao"
3、namespace的地址一定要和目录中的地址相对应
4、将UTF-8改成UTF8