@[TOC](Invalid bound statement (not found): com.example.springbootssmtest.mapper.UsersMapper.insertUser)
问题
在使用idea做springboot开发的时候,遇到Invalid bound statement (not found): com.example.springbootssmtest.mapper.UsersMapper.insertUser,但是mybaits、xml文件语法无误,接口和xml文件的路径对应无误,主程序也使用@MapperScan(“com.example.springbootssmtest.mapper”)对接口进行了扫描。idea提示上述异常,说明接口方法没问题,问题在于xml文件
原因
通过查阅相关资料发现,IDEA对xml文件处理的方式不同,在Eclipse中dao文件与mapper.xml文件只要在同一级目录下即可,但是在IDEA中,mapper.xml要放在resources目录下,且还有一个关键的地方是什么吧?就是resources下不能创建package,只能创建Directory,文件夹下面要想创建文件夹,就不能以(.)的形式,例如com.example.springbootssmtest.mapper,在src目录下可以创建package这样连着写包名,但是在resources下面就不能这样写了,这样写的话,就相当于这个文件夹的名称是“com.example.springbootssmtest.mapper”
,而不是com/example/springbootssmtest/mapper
。
解决办法1
在resources下一级一级的创建directory,先建com,然后在com下创建example,然后在example下创建。。。
创建完成directory后,在里面添加xml文件便可。
解决办法2
将接口方法和xml文件放到一起,在mapper接口上添加@mapper注解
主程序添加接口扫描@MapperScan(“com.example.springbootssmtest.mapper”)
解决办法3
直接在resources下创建一个名字为mapper的directory,然后在配置文件里添加mybatis.mapper.locations配置
参考:https://blog.csdn.net/benben513624/article/details/81076182