From 50d9ebf2801d6c3c4d96105829a44d15696e135d Mon Sep 17 00:00:00 2001 From: samyge Date: Wed, 5 Jul 2023 23:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3Mapper=E7=88=B6=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E6=B3=9B=E5=9E=8B=E4=BF=A1=E6=81=AF=E5=9C=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=B3=9B=E5=9E=8B=E7=9A=84=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E4=B8=8B=E6=8A=A5ClassCastException=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8Cfixed=20#886?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/mapper/mapperhelper/MapperTemplate.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java index 195c8333f..55a5fa253 100644 --- a/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java +++ b/core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java @@ -167,7 +167,18 @@ public Class getEntityClass(MappedStatement ms) { if (type instanceof ParameterizedType) { ParameterizedType t = (ParameterizedType) type; if (t.getRawType() == this.mapperClass || this.mapperClass.isAssignableFrom((Class) t.getRawType())) { - Class returnType = (Class) t.getActualTypeArguments()[0]; + Type actualType = t.getActualTypeArguments()[0]; + Class returnType; + if (actualType instanceof Class) { + returnType = (Class) actualType; + } else if (actualType instanceof ParameterizedType) { + // 获取泛型信息后发现任然是泛型的场景 + returnType = (Class) ((ParameterizedType)actualType).getRawType(); + } else { + // GenericArrayType、TypeVariable以及WildcardType不受支持 + throw new MapperException(msId + " 方法的泛型信息不受支持!"); + } + //获取该类型后,第一次对该类型进行初始化 EntityHelper.initEntityNameMap(returnType, mapperHelper.getConfig()); entityClassMap.put(msId, returnType);