spring boot和mybatis整合时报org.apache.ibatis.binding.BindingException: Invalid bound statement (not f...

问题:

spring boot和mybatis整合时报:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)


解决方法:

出现这种错误,应该是mapper接口和对应的xml文件没有绑定,目前知道的有两种可能的原因:

  1. 在xml文件中,namespace或代表相应方法的id属性跟mapper接口没有对应
  2. 编译后,查看target中的文件,很有可能是没有生产对应的xml文件。如果是这种情况,需要在你的pom.xml的里面添加如下代码:
        
            
                src/main/java
                
                    **/*.xml
                
                true
            
        

补充:

  1. 在application.yml文件中需要配置mybatis.mapper-locations:,如
mybatis:
  mapper-locations: mapper-locations: classpath*:mapper/*.xml

代表mybatis需要的xml文件的路径。

  1. 在配置类上加注解@MapperScan,如
@MapperScan("dao")

代表mybatis需要的mapper接口的路径。

你可能感兴趣的:(spring boot和mybatis整合时报org.apache.ibatis.binding.BindingException: Invalid bound statement (not f...)