Type interface mapper.UserMapper is not known to the MapperRegistry.
分1:没有引入Mapper.xml
解决
分析2:没有引入Mapper接口路径
解决
总结
Table 'mybatis.tb_calzz' doesn't exist
错误提示
分析
Error querying database. ...Query was empty
原因
解决
分1:没有引入Mapper.xml
解决
分析2:没有引入Mapper接口路径
解决
总结
Table 'mybatis.tb_calzz' doesn't exist
错误提示
分析
Error querying database. ...Query was empty
原因
解决
Type interface mapper.UserMapper is not known to the MapperRegistry.
1 | org.apache.ibatis.binding.BindingException: Type interface mapper.UserMapper is not known to the MapperRegistry. |
分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
<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
<!-- 该配置文件包含对 MyBatis 系统的核心设置 -->
<configuration>
......
<mappers>
<mapper class="mapper.ClazzMapper"/>
<mapper class="mapper.StudentMapper"/>
</mappers>
......
</configuration>
总结
引入Mapper.xml
映射文件,使用resource
属性,而引入接口则使用class
属性.
Table ‘mybatis.tb_calzz’ doesn’t exist
错误提示
1 | DEBUG [main] ==> Preparing: select * from tb_student where id=? |
分析
提示很明显,说mybatis
数据库中不存在tb_calzz
这个表.这种情况:
- 要么是这个表不存在,如果是这样,创建进入数据库,创建这个表即可。
- 要么是
SQL
中这个表名字打错了,这种情况,修改SQL
语句,把表名改为正确的表名即可.
Error querying database. …Query was empty
1 | org.apache.ibatis.exceptions.PersistenceException: |
原因
映射文件mapper/UserMapper.xml
中id
为selectUserById
的select
标签中没有写SQL
语句。
解决
写上SQL
语句即可。