Mybatis source code analysis: static class MethodSignature role in internal MapperMethod

MethodSignature analysis

  Providing three MethodSignature role MapperMethod class name acquiring parameters to be executed and the process parameters @Param annotations marked, obtaining parameters marked with the @MapKey (@MapKey role in the follow will be mentioned), the return type of the method, obtaining when necessary flag SELECT operations. Here are all the attributes of MethodSignature.

  • private final boolean returnsMany; // whether the multi-value query
  • private final boolean returnsMap; // query whether the map
  • private final boolean returnsVoid; // query whether the void
  • private final boolean returnsCursor; // if the cursor query
  • private final Class returnType <?>; // return type
  • private final String mapKey; // get the value of mapKey
  • private final Integer resultHandlerIndex;
  • private final Integer rowBoundsIndex;
  • private final ParamNameResolver paramNameResolver; // parameter parser

  Observe the following code, the constructor first obtain the return type, the reference value acquired mapperInterface itself and all of the parent and all types of interfaces to find the type of the parameter parser to return, provides three types Mybatis implemented ParameterizedType for, of TypeVariable, GenericArrayType . When the type of the value returned by subsequent SElECT to determine what will be done query, void query, Map query, the cursor query, multi-valued query, this will be marking to the relevant properties, perform exeute in mapperMethod () method will judge. Mapper constructor method also checks to be performed if there is marked @Mapkey notes, if the result of this means that the return type is a Map.

 1    public MethodSignature(Configuration configuration, Class<?> mapperInterface, Method method) {
 2         //解析返回的类型 ParameterizedType,TypeVariable,GenericArrayType
 3       Type resolvedReturnType = TypeParameterResolver.resolveReturnType(method, mapperInterface);
 4       if (resolvedReturnType instanceof Class<?>) {
 5         this.returnType = (Class<?>) resolvedReturnType;
 6       } else if (resolvedReturnType instanceof ParameterizedType) {
 7         this.returnType = (Class<?>) ((ParameterizedType for) resolvedReturnType) .getRawType ();
 . 8        } the else {
 . 9          the this .returnType = Method.getReturnType ();
 10        }
 . 11        the this .returnsVoid = void . Class .equals ( the this .returnType);
 12 is        // whether collection or array type 
13 is        the this .returnsMany = configuration.getObjectFactory () IsCollection (. the this .returnType) || the this .returnType.isArray ();
 14        // determines whether the type of cursor 
15        the this .returnsCursor = the cursor. class.equals ( the this .returnType);
 16        // Get MapKey annotation 
. 17        the this .mapKey = getMapKey (Method);
 18 is        // determines whether or not mapkey NULL 
. 19        the this .returnsMap = the this .mapKey =! null ;
 20 is        the this .rowBoundsIndex = getUniqueParamIndex (Method, RowBounds. class );
 21 is        the this .resultHandlerIndex = getUniqueParamIndex (Method, the ResultHandler. class );
 22 is        // initialization parameter name parser 
23 is        the this .paramNameResolver = new new ParamNameResolver(configuration, method);
24     }

 

Guess you like

Origin www.cnblogs.com/zhengzuozhanglina/p/11223568.html