Invalid bound statement (not found)

遇到这个问题是我在搭建spring  boot+mybatis后做测试遇到的

1.检查xml文件所在package名称是否和Mapper interface所在的包名

<mapper namespace="me.tspace.pm.dao.UserDao">

  mapper的namespace写的不对!!!

2.UserDao的方法在UserDao.xml中没有,然后执行UserDao的方法会报此

3.UserDao的方法返回值是List<User>,而select元素没有正确配置ResultMap,或者只配置ResultType!

4.看下mapper的XML配置路径是否正确

5.Mapper文件

   1)sql中有;

   2)注意resultMap或者是resultType 这是返回值,包括参数记得查看是否正确

6.还有一种情况就是mapper文件没有扫描到

   请查看我的这篇文章https://blog.csdn.net/AinUser/article/details/81533858

7.mapper.xml的namespace要写所映射接口的全称类名

8.mapper.xml中的每个statement的id要和接口方法的方法名相同

9.mapper.xml中定义的每个sql的parameterType要和接口方法的形参类型相同

10.mapper.xml中定义的每个sql的resultType要和接口方法的返回值的类型相同

11.mapper.xml的命名规范遵守: 接口名+Mapper.xml(两者名字需匹配UserMapper,UserMapper.xml)

12。如果不是使用mybatis的注解,有mapper文件的话,需要指定下路径

mybatis:
  mapper-locations: classpath:com/read/read_data_web/dao/*2.xml
  type-aliases-package: com/read/read_data_web/entity

13.我的原因是:我将@Service注解添加到了接口上面了,而不是实现类上面(赶脚不会有人跟我犯同样的错吧)

14.最后呢,我说一个测试的方案吧(下面的UserService可以改成UserMapper作为junit测试吧)

@SpringBootApplication
//@MapperScan("com.read.read_data_web.dao")
//@ComponentScan(basePackages = {"com.read.read_data_web.service"})
public class ReadDataWebApplication {

    public static void main(String[] args) {
        SpringApplication.run(ReadDataWebApplication.class, args);
        //test测试
        /*UserService user = context.getBean(UserService.class);
        int result = user.findData_user();
        System.out.println(result);*/
    }
}

有其他情况,请留言下方,我坐下整合,非常感谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值