Mapped Statements collection does not contain value for

Mapped Statements collection does not contain value for,第1张

Mapped Statements collection does not contain value for
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.example.demo.dao.impl.DepartmentDaoImpl.getById
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.example.demo.dao.impl.DepartmentDaoImpl.getById

产生这种错误的原因一般有二点:

1.是mapper.xml文件的namespace没有与实现接口相对应。

2.在接口的实现方法中没有正确填写对应xml文件的namespace。

3.还有一个原因是 spring没有扫描到mapper.xml。这一般与mybatis的 mapper-locations 配置相关。

(1)如果pom.xml使用的是: mybatis-spring-boot-starter 则yml文件中应该配置 mybatis:mapper-locations: classpath:mapper/*.xml

   org.mybatis.spring.boot
     mybatis-spring-boot-starter
     2.2.1
 
(2)如果如果pom.xml使用的是:mybatis-plus-boot-starter 则yml中应该配置 mybatis-plus:mapper-locations: classpath:mapper/*.xml

    com.baomidou
    mybatis-plus-boot-starter
    3.3.1

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5692836.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存