Skip to content

Commit 50d9ebf

Browse files
committed
解决Mapper父接口的泛型信息在使用泛型的场景下报ClassCastException的问题,fixed #886
1 parent f08d996 commit 50d9ebf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

core/src/main/java/tk/mybatis/mapper/mapperhelper/MapperTemplate.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,18 @@ public Class<?> getEntityClass(MappedStatement ms) {
167167
if (type instanceof ParameterizedType) {
168168
ParameterizedType t = (ParameterizedType) type;
169169
if (t.getRawType() == this.mapperClass || this.mapperClass.isAssignableFrom((Class<?>) t.getRawType())) {
170-
Class<?> returnType = (Class<?>) t.getActualTypeArguments()[0];
170+
Type actualType = t.getActualTypeArguments()[0];
171+
Class<?> returnType;
172+
if (actualType instanceof Class) {
173+
returnType = (Class<?>) actualType;
174+
} else if (actualType instanceof ParameterizedType) {
175+
// 获取泛型信息后发现任然是泛型的场景
176+
returnType = (Class<?>) ((ParameterizedType)actualType).getRawType();
177+
} else {
178+
// GenericArrayType、TypeVariable以及WildcardType不受支持
179+
throw new MapperException(msId + " 方法的泛型信息不受支持!");
180+
}
181+
171182
//获取该类型后,第一次对该类型进行初始化
172183
EntityHelper.initEntityNameMap(returnType, mapperHelper.getConfig());
173184
entityClassMap.put(msId, returnType);

0 commit comments

Comments
 (0)