mybatis使用InsertProvider注解报错解决过程

        目前项目在使用mybatis,并且是使用注解的方式。在使用InsertProvider注解的时候报了一下的错误:org.apache.ibatis.builder.BuilderException: Could not find value method on SQL annotation.  Cause: org.apache.ibatis.builder.BuilderException: Error creating SqlSource for SqlProvider. Method........

       注解是如下这个样子的

@InsertProvider(method = "insertlist",type=SqlProvider.class)
 public int insertInnerTable(List list,String dbTable);

        思路是要写一个通用的插入一个集合的方法,但是在执行的时候就报了上面的错误。在网上查资料未果。于是只能自己动手,丰衣足食了。一步步跟断点,跟到mybatis了报错的方法中,发现了如下的代码

try {
      this.sqlSourceParser = new SqlSourceBuilder(config);
      this.providerType = (Class<?>) provider.getClass().getMethod("type").invoke(provider);
      providerMethodName = (String) provider.getClass().getMethod("method").invoke(provider);

      for (Method m : this.providerType.getMethods()) {
        if (providerMethodName.equals(m.getName())) {
          if (m.getParameterTypes().length < 2
              && m.getReturnType() == String.class) {
            this.providerMethod = m;
            this.providerTakesParameterObject = m.getParameterTypes().length == 1;
          }
        }
      }
    } catch (Exception e) {
      throw new BuilderException("Error creating SqlSource for SqlProvider.  Cause: " + e, e);
    }

        注意标黄的位置,终于发现导致错误的罪魁祸首了,原来是这里限制了参数的个数,不能操作两个参数的啊。

        于是将方法以及注解改为如下形式

@InsertProvider(method = "insert",type=SqlProvider.class)
 public int insert(SqlContext sqlContext);

在SqlProvider中对应的方法为

public String insert(SqlContext sqlContext){

      ........

}

至此问题解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值