Type interface mapper.UserMapper is not known to the MapperRegistry.
1 2 3 4 5
| org.apache.ibatis.binding.BindingException: Type interface mapper.UserMapper is not known to the MapperRegistry. at org.apache.ibatis.binding.MapperRegistry.getMapper(MapperRegistry.java:47) at org.apache.ibatis.session.Configuration.getMapper(Configuration.java:745) at org.apache.ibatis.session.defaults.DefaultSqlSession.getMapper(DefaultSqlSession.java:292) at test.ManyToManyTest.main(ManyToManyTest.java:18)
|
分1:没有引入Mapper.xml
这是因为没有在mybatis-config.xml
中引入UserMapper.xml.
解决
在mybatis
根配置文件mybatis-config.xml
中,引入UserMapper.xml
即可:<mapper resource="mapper/UserMapper.xml"/>
1 2 3 4 5 6 7 8 9
| <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd" > <configuration> ...... <mappers> <mapper resource="mapper/UserMapper.xml"/> </mappers> ...... </configuration>
|
分析2:没有引入Mapper接口路径
解决
引入StudentMapper.java
接口即可:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration> ...... <mappers> <mapper class="mapper.ClazzMapper"/> <mapper class="mapper.StudentMapper"/> </mappers> ...... </configuration>
|
总结
引入Mapper.xml
映射文件,使用resource
属性,而引入接口则使用class
属性.
Table ‘mybatis.tb_calzz’ doesn’t exist
错误提示
1 2 3 4 5 6 7 8 9 10
| DEBUG [main] ==> Preparing: select * from tb_student where id=? DEBUG [main] ==> Parameters: 1(Integer) DEBUG [main] ====> Preparing: select * from tb_calzz where id=? DEBUG [main] ====> Parameters: 1(Integer) org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mybatis.tb_calzz' doesn't exist ### The error may exist in mapper/ClazzMapper.java (best guess) ### The error may involve mapper.ClazzMapper.selectClazzById-Inline ### The error occurred while setting parameters ### SQL: select * from tb_calzz where id=?
|
分析
提示很明显,说mybatis
数据库中不存在tb_calzz
这个表.这种情况:
- 要么是这个表不存在,如果是这样,创建进入数据库,创建这个表即可。
- 要么是
SQL
中这个表名字打错了,这种情况,修改SQL
语句,把表名改为正确的表名即可.
Error querying database. …Query was empty
1 2 3 4 5 6
| org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Query was empty ### The error may exist in mapper/UserMapper.xml ### The error may involve mapper.UserMapper.selectUserById-Inline ### The error occurred while setting parameters ### SQL:
|
原因
映射文件mapper/UserMapper.xml
中id
为selectUserById
的select
标签中没有写SQL
语句。
解决
写上SQL
语句即可。