Skip to content

Commit

Permalink
Merge pull request #887 from samyge/master
Browse files Browse the repository at this point in the history
解决Mapper父接口的泛型信息在使用泛型的场景下报ClassCastException的问题,fixed #886
  • Loading branch information
abel533 authored Jul 6, 2023
2 parents f08d996 + 50d9ebf commit 5e31029
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5e31029

Please sign in to comment.