项目场景:
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