发生这样的问题原因有以下几点
1.mapper接口类全名与mapper.xml的namespace不一致
2.mapper接口的方法与mapper.xml的id不一致
3.mapper.xml的中文注释造成(去掉中文注释)
4.mapper.xml的路径与配置的不一致
例如: mapper.xml位置在resources/mapper/mapper.xml但是你的mybatis
正确配置确
mybatis:
mapperLocations:classpath:mapper/*/*.xml
这样只能扫描到不到mapper/mapper.xml 正确的配置是 mybatis: mapperLocations: classpath:mapper/.xml或者将mapper.xml放到resources/mapper//mapper.xml的位置(*表示任何文件夹名称)
5.idea中的resources有个标志如果没有则需要设置成resources
选择file-->Project Structure-->Moudules-->选择项目的resources文件夹-->点击Resources-->ok
6.一个简单的关于mybatis的application.yml配置
mybatis:
mapperLocations: /mapper/*.xml
typeAliasesPackage: com.test.hfdy.entity
configuration:
map-underscore-to-camel-case: true
lazy-loading-enabled: false
注意:本文归作者所有,未经作者允许,不得转载