mybatis
在 application.yml
的具体配置如下所示:
mybatis:
config-location: classpath:mybatis/mybatis-config.xml
mapper-locations: classpath*:mybatis/mapper/mysql/**/**.xml
type-aliases-package: com.dragonflyxd.lr.web.model.entity
在项目的入口 LrWebApplication
中也有添加扫描mapper文件的注解:
@MapperScan("com.dragonflyxd.lr.web.dal.**")
Dao层的代码结构截图如下所示:
mybatis-config文件的具体内容如下:
CategoryMapper的Mapper和xml的具体内容如下所示:
调用 /category/test
接口的时候,出现 "Invalid bound statement (not found): com.dragonflyxd.lr.web.dal.CategoryMapper.count"
的问题。
- Mapper文件中的方法都已经在xml中对应。
- xml文件的命名空间对应的是Mapper的包路径。
- 项目启动后,Mapper和xml文件能确定已经被编译。
后经排查,发现是由于 xml 文件没找到的原因。
因为我在工程里建的
mapper.mysql
是个文件夹的名字,而不是包名,不符合mapper-locations: classpath*:mybatis/mapper/mysql/**/**.xml
。另说明,在
IDEA
里,resources下的目录,包名和文件名都可以使用 . ,见如下截图: