mybatis3.3@sqlprovider nested exception is java.lang.NumberFormatException: null

使用@selectprovider的时候,方法中传了两个参数,然后编译时报错。

经查看 Itype @cjm0000000大神的博客http://qurey.iteye.com/blog/1944785后才懂得,

原来mybatis3.3中selectprovider中type类的方法的参数只能小于2个(标红的部分):

org.apache.ibatis.builder.annotation.ProviderSqlSource

[java] view plain copy
  1. public ProviderSqlSource(Configuration config, Object provider) {  
  2.     String providerMethodName = null;  
  3.     try {  
  4.       this.sqlSourceParser = new SqlSourceBuilder(config);  
  5.       this.providerType = (Class<?>) provider.getClass().getMethod("type").invoke(provider);  
  6.       providerMethodName = (String) provider.getClass().getMethod("method").invoke(provider);  
  7.   
  8.       for (Method m : this.providerType.getMethods()) {  
  9.         if (providerMethodName.equals(m.getName())) {  
  10.           <span style="color:#ff0000;">if (m.getParameterTypes().length < 2  
  11.               && m.getReturnType() == String.class) </span>{  
  12.             this.providerMethod = m;  
  13.             this.providerTakesParameterObject = m.getParameterTypes().length == 1;  
  14.           }  
  15.         }  
  16.       }  
  17.     } catch (Exception e) {  
  18.       throw new BuilderException("Error creating SqlSource for SqlProvider.  Cause: " + e, e);  
  19.     }  
  20.     if (this.providerMethod == null) {  
  21.       throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"  
  22.           + providerMethodName + "' not found in SqlProvider '" + this.providerType.getName() + "'.");  
  23.     }  
  24.   }  
而mybatis3.4中的代码就取消了参数个数限制:
[java] view plain copy
  1. public ProviderSqlSource(Configuration config, Object provider) {  
  2.     String providerMethodName;  
  3.     try {  
  4.       this.sqlSourceParser = new SqlSourceBuilder(config);  
  5.       this.providerType = (Class<?>) provider.getClass().getMethod("type").invoke(provider);  
  6.       providerMethodName = (String) provider.getClass().getMethod("method").invoke(provider);  
  7.   
  8.       for (Method m : this.providerType.getMethods()) {  
  9.         if (providerMethodName.equals(m.getName())) {  
  10.           <span style="color:#ff0000;">if (m.getReturnType() == String.class) </span>{  
  11.             if (providerMethod != null){  
  12.               throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"  
  13.                       + providerMethodName + "' is found multiple in SqlProvider '" + this.providerType.getName()  
  14.                       + "'. Sql provider method can not overload.");  
  15.             }  
  16.             this.providerMethod = m;  
  17.             this.providerMethodArgumentNames = new ParamNameResolver(config, m).getNames();  
  18.           }  
  19.         }  
  20.       }  
  21.     } catch (BuilderException e) {  
  22.       throw e;  
  23.     } catch (Exception e) {  
  24.       throw new BuilderException("Error creating SqlSource for SqlProvider.  Cause: " + e, e);  
  25.     }  
  26.     if (this.providerMethod == null) {  
  27.       throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"  
  28.           + providerMethodName + "' not found in SqlProvider '" + this.providerType.getName() + "'.");  
  29.     }  
  30.   }  
所以,在mybatis3.3中使用@sqlprovider传多个参数时,要么直接用实体bean替换,要么用Map包装一下。

虽拾人牙慧,但自己再记一下有助自己提高。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值