BindingException: Invalid bound statement

在使用Mybatis-plus进行测试时遇到`BindingException`,原因是application.yml中的`mapper-locations`配置错误。解决方法是修正XML文件路径,正确设置为`classpath*:mapper/**/*.xml`。
摘要由CSDN通过智能技术生成

项目场景:

Mybatis-plus学习


问题描述

测试时遇到org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mp.mapper.UserMapper.updateBalanceByIds

@Test
    void testCustomSqlUpdate() {
        List<Long> ids = List.of(1L, 2L, 4L);
        int amount = 200;
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<User>().in(User::getId, ids);
        userMapper.updateBalanceByIds(wrapper, amount);
    }

原因分析:

查了一下发现是找不到映射的文件

于是首先看了启动类有无扫描包

@MapperScan("com.mp.mapper")
@SpringBootApplication
public class MpDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(MpDemoApplication.class, args);
    }

}

扫描包有了,不是这个问题

mapper里的方法也检查过了,没有什么问题,而sql出错不会出现这个错误提示


解决方案:

结果发现是application.yml配置文件里出现了问题

mybatis-plus:
  mapper-locations: classpath*:mapper/**/.xml
  type-aliases-package: com.itheima.mp.domain.po  #扫描包
  configuration:
    map-underscore-to-camel-case: true   #驼峰命名映射
    cache-enabled: false   #二级缓存
  global-config:
    db-config:
      id-type: assign_id   #雪花算法
      update-strategy: not_null   #只更新非空字段

mapper-locations那一行.xml前面写错了,应该改为

mapper-locations: classpath*:mapper/**/*.xml
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值