奇葩问题:Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey

使用mybatis,遇到Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey 这个问题,困扰了我好几天,在网上找了许多方法使用没有解决。

这个问题不好查,会报这个错的原因太多了,网友整理的查找原因方法如下:

1、检查mapper.xml文件中<mapper namespace="xxxMapper"> 标签是否指向了正确的mapper接口;

   我的是正确的
2、检查是否正确显式指定mapper接口所在位置

      方式一:启动类上添加注解@MapperScan(“com.xxs.shirodemo.dao”)

      方式二:在每一个mapper接口上添加注解@Mapper

3、检查mapper.xml的配置路径是否正确

           mybatis:
                mapper-locations: classpath*:mapping/*.xml

4、检查mapper接口中的方法名与mapper.xml中操作的id是否相同、是否有一方缺少。

我的问题就出在第3条,我把mybaits配置放在了spring:  下,其实要单独拉出来与spring并列

如图

spring:
  datasource:
       ……
  freemarker:
       ……

mybatis:
      mapper-locations: classpath*:mapper/*.xml
      type-aliases-package: cn.zss.zsdemo.entity

#log4j2
logging:
   config: classpath:log4j2.xml
View Code

 



posted @ 2019-11-15 11:41  小芝麻开花  阅读(665)  评论(0编辑  收藏  举报