Mybatis笔记二:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

时间:2022-05-22 10:15:23

错误异常:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.dao.NarCodeMapper.getNarCode

出现这个原因:Mybatis的Mapper interface和xml文件的定义对应不上

大致通过如下几步来检查:

1.Mapper interface(接口)名称和Mapper xml名称是否保持一致

-------------------------------------------------------------------------------------------------------------------------------------------------------

<?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="com/test/xml/NarCodeMapper.xml"/>
  </mappers>
</configuration>

-----------------------------------------------------------

package com.test.dao;

public interface NarCodeMapper {
 
}

-------------------------------------------------------------------------------------------------------------------------------------------------------

2.Mapper xml中namespace属性值是否和Mapper interface(接口)所在(package名称+接口名称)保持一致。(本人就是在这里大意)

-------------------------------------------------------------------------------------------------------------------------------------------------------

<mapper namespace="com.test.dao.NarCodeMapper">

</mapper>

-----------------------------------------------------------

package com.test.dao;

public interface NarCodeMapper {
 
}

-------------------------------------------------------------------------------------------------------------------------------------------------------

3.Mapper interface(接口)中的函数是否与Mapper xml中(select,update,insert,delete)标签中的id属性值对应

4.去掉xml文件中文注释

5.随意在xml文件中加一个空格或者空行然后保存