使用@selectprovider的时候,方法中传了两个参数,然后编译时报错。
经查看 Itype @cjm0000000大神的博客http://qurey.iteye.com/blog/1944785后才懂得,
原来mybatis3.3中selectprovider中type类的方法的参数只能小于2个(标红的部分):
org.apache.ibatis.builder.annotation.ProviderSqlSource
- 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() + "'.");
- }
- }
- 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() + "'.");
- }
- }
虽拾人牙慧,但自己再记一下有助自己提高。