当前使用版本(必填,否则不予处理)
Mybatis-Plus3.5.5
该问题是如何引起的?(确定最新版也有问题再提!!!)
Mybatis-Plus3.5.5 版本在扩展DefaultSqlInjector时,无法调用扩展的Mapper方法
重现步骤(如果有就写完整)
1、定义扩展类 @Component public class InsertBatchSqlInjector extends DefaultSqlInjector {
@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
// super.getMethodList() 保留 Mybatis Plus 自带的方法
List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
// 添加自定义方法:批量插入,方法名为 insertBatchSomeColumn
methodList.add(new InsertBatchSomeColumn());
return methodList;
}
}
2、定义Mapper
public interface MyBaseMapper
// 批量插入
int insertBatchSomeColumn(Collection<T> batchList);
}
3、继承MyBaseMapper
public interface DemoMapper extends MyBaseMapper
}
4、设置sqlInjector @Override public void run(String... args) { Configuration configuration = sessionFactory.getConfiguration(); GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration); globalConfig.setSqlInjector(insertBatchSqlInjector); }
5、调用insertBatchSomeColumn方法 demoMapper.insertBatchSomeColumn(list))
报错信息
在调用demoMapper.insertBatchSomeColumn(list))时,报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):demo.mapper.DemoMapper.insertBatchSomeColumn
at org.apache.ibatis.binding.MapperMethod$SqlCommand.
Comment From: miemieYaho
你那个步骤4是个啥?画蛇添足是吧
Comment From: chaobingliu
老师,这是因为步骤一定义的组件没有生效。 我是手工将自定义的SqlInjector设置到globalConfig中。但依然没有生效。
Comment From: miemieYaho
https://gitee.com/baomidou/mybatis-plus-samples/tree/master/mybatis-plus-sample-sql-injector