Invalid bound statement (not found): com.example.springbootssmtest.mapper.UsersMapper.insertUser

@[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

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值