mybatis3.3@sqlprovider nested exception is java.lang.NumberFormatException: null
2018-03-29 14:47
543 查看
使用@selectprovider的时候,方法中传了两个参数,然后编译时报错。
经查看 Itype @cjm0000000大神的博客http://qurey.iteye.com/blog/1944785后才懂得,
原来mybatis3.3中selectprovider中type类的方法的参数只能小于2个(标红的部分):
org.apache.ibatis.builder.annotation.ProviderSqlSource
[java] view plain copy public ProviderSqlSource(Configuration config, Object provider) {
String providerMethodName = null;
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())) {
<span style="color:#ff0000;">if (m.getParameterTypes().length < 2
&& m.getReturnType() == String.class) </span>{
this.providerMethod = m;
this.providerTakesParameterObject = m.getParameterTypes().length == 1;
}
}
}
} catch (Exception e) {
throw new BuilderException("Error creating SqlSource for SqlProvider. Cause: " + e, e);
}
if (this.providerMethod == null) {
throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"
+ providerMethodName + "' not found in SqlProvider '" + this.providerType.getName() + "'.");
}
}
而mybatis3.4中的代码就取消了参数个数限制:[java] view plain copy public ProviderSqlSource(Configuration config, Object provider) {
String providerMethodName;
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())) {
<span style="color:#ff0000;">if (m.getReturnType() == String.class) </span>{
if (providerMethod != null){
throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"
+ providerMethodName + "' is found multiple in SqlProvider '" + this.providerType.getName()
+ "'. Sql provider method can not overload.");
}
this.providerMethod = m;
this.providerMethodArgumentNames = new ParamNameResolver(config, m).getNames();
}
}
}
} catch (BuilderException e) {
throw e;
} catch (Exception e) {
throw new BuilderException("Error creating SqlSource for SqlProvider. Cause: " + e, e);
}
if (this.providerMethod == null) {
throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"
+ providerMethodName + "' not found in SqlProvider '" + this.providerType.getName() + "'.");
}
}
所以,在mybatis3.3中使用@sqlprovider传多个参数时,要么直接用实体bean替换,要么用Map包装一下。
虽拾人牙慧,但自己再记一下有助自己提高。
经查看 Itype @cjm0000000大神的博客http://qurey.iteye.com/blog/1944785后才懂得,
原来mybatis3.3中selectprovider中type类的方法的参数只能小于2个(标红的部分):
org.apache.ibatis.builder.annotation.ProviderSqlSource
[java] view plain copy public ProviderSqlSource(Configuration config, Object provider) {
String providerMethodName = null;
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())) {
<span style="color:#ff0000;">if (m.getParameterTypes().length < 2
&& m.getReturnType() == String.class) </span>{
this.providerMethod = m;
this.providerTakesParameterObject = m.getParameterTypes().length == 1;
}
}
}
} catch (Exception e) {
throw new BuilderException("Error creating SqlSource for SqlProvider. Cause: " + e, e);
}
if (this.providerMethod == null) {
throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"
+ providerMethodName + "' not found in SqlProvider '" + this.providerType.getName() + "'.");
}
}
而mybatis3.4中的代码就取消了参数个数限制:[java] view plain copy public ProviderSqlSource(Configuration config, Object provider) {
String providerMethodName;
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())) {
<span style="color:#ff0000;">if (m.getReturnType() == String.class) </span>{
if (providerMethod != null){
throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"
+ providerMethodName + "' is found multiple in SqlProvider '" + this.providerType.getName()
+ "'. Sql provider method can not overload.");
}
this.providerMethod = m;
this.providerMethodArgumentNames = new ParamNameResolver(config, m).getNames();
}
}
}
} catch (BuilderException e) {
throw e;
} catch (Exception e) {
throw new BuilderException("Error creating SqlSource for SqlProvider. Cause: " + e, e);
}
if (this.providerMethod == null) {
throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"
+ providerMethodName + "' not found in SqlProvider '" + this.providerType.getName() + "'.");
}
}
所以,在mybatis3.3中使用@sqlprovider传多个参数时,要么直接用实体bean替换,要么用Map包装一下。
虽拾人牙慧,但自己再记一下有助自己提高。
相关文章推荐
- mybatis中SQL语句单双引号的问题java.lang.NumberFormatException: For input string: "Y"
- welogic不能启动主服务器,出现 java.lang.NumberFormatException: null错误
- java.lang.NumberFormatException: null
- Request processing failed; nested exception is java.lang.NullPointerException] with root cause
- [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
- java.lang.NumberFormatException: null原因
- HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
- Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: null
- java.lang.NumberFormatException null
- java.lang.NumberFormatException: null
- Unknown jedis exception; nested exception is java.lang.NullPointerException
- HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
- java.lang.NumberFormatException: null
- SQL [ ]; SQL state [null]; error code [17004]; 无效的列类型; nested exception is java.sql.SQLException: 无效
- 页面提交错误,页面间参数传递java.lang.NumberFormatException: null
- Request processing failed; nested exception is java.lang.NullPointerException
- 关于使用mybatis传值时出现java.lang.NumberFormatException: For input string: "C"报错记录
- Could not open JPA EntityManager for transaction; nested exception is java.lang.NullPointerException
- nested exception is java.lang.NullPointerException
- 报错SQL state [null]; error code [17027]; 流已被关闭; nested exception is java.sql.SQLException: 流已被关闭