Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

解决Mapper父接口的泛型信息在使用泛型的场景下报ClassCastException的问题,fixed #886 #887

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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