mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 12:18:01 +08:00
Merge branch 'v6-dev' of gitee.com:dromara/hutool into v6-dev
This commit is contained in:
commit
3ce8b1dc0b
@ -52,7 +52,11 @@ public class TypeUtil {
|
|||||||
} else if (type instanceof ParameterizedType) {
|
} else if (type instanceof ParameterizedType) {
|
||||||
return (Class<?>) ((ParameterizedType) type).getRawType();
|
return (Class<?>) ((ParameterizedType) type).getRawType();
|
||||||
} else if (type instanceof TypeVariable) {
|
} else if (type instanceof TypeVariable) {
|
||||||
return (Class<?>) ((TypeVariable<?>) type).getBounds()[0];
|
//return (Class<?>) ((TypeVariable<?>) type).getBounds()[0];
|
||||||
|
final Type[] bounds = ((TypeVariable<?>) type).getBounds();
|
||||||
|
if (bounds.length == 1) {
|
||||||
|
return getClass(bounds[0]);
|
||||||
|
}
|
||||||
} else if (type instanceof WildcardType) {
|
} else if (type instanceof WildcardType) {
|
||||||
final Type[] upperBounds = ((WildcardType) type).getUpperBounds();
|
final Type[] upperBounds = ((WildcardType) type).getUpperBounds();
|
||||||
if (upperBounds.length == 1) {
|
if (upperBounds.length == 1) {
|
||||||
|
@ -82,6 +82,19 @@ public class TypeUtilTest {
|
|||||||
Assertions.assertEquals(Long.class, idType);
|
Assertions.assertEquals(Long.class, idType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getClasses() {
|
||||||
|
Method method = MethodUtil.getMethod(Parent.class, "getLevel");
|
||||||
|
Type returnType = TypeUtil.getReturnType(method);
|
||||||
|
Class<?> clazz = TypeUtil.getClass(returnType);
|
||||||
|
Assertions.assertEquals(Level1.class, clazz);
|
||||||
|
|
||||||
|
method = MethodUtil.getMethod(Level1.class, "getId");
|
||||||
|
returnType = TypeUtil.getReturnType(method);
|
||||||
|
clazz = TypeUtil.getClass(returnType);
|
||||||
|
Assertions.assertEquals(Object.class, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
public static class Level3 extends Level2<Level3>{
|
public static class Level3 extends Level2<Level3>{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -95,4 +108,9 @@ public class TypeUtilTest {
|
|||||||
private T id;
|
private T id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Parent<T extends Level1<B>, B extends Long> {
|
||||||
|
private T level;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
package org.dromara.hutool.extra.aop.engine.spring;
|
package org.dromara.hutool.extra.aop.engine.spring;
|
||||||
|
|
||||||
|
import org.dromara.hutool.core.exception.ExceptionUtil;
|
||||||
import org.dromara.hutool.extra.aop.Aspect;
|
import org.dromara.hutool.extra.aop.Aspect;
|
||||||
import org.dromara.hutool.extra.aop.SimpleInterceptor;
|
import org.dromara.hutool.extra.aop.SimpleInterceptor;
|
||||||
import org.springframework.cglib.proxy.MethodInterceptor;
|
import org.springframework.cglib.proxy.MethodInterceptor;
|
||||||
@ -47,10 +48,15 @@ public class SpringCglibInterceptor extends SimpleInterceptor implements MethodI
|
|||||||
if (aspect.before(target, method, args)) {
|
if (aspect.before(target, method, args)) {
|
||||||
try {
|
try {
|
||||||
result = proxy.invoke(target, args);
|
result = proxy.invoke(target, args);
|
||||||
} catch (final InvocationTargetException e) {
|
} catch (final Throwable e) {
|
||||||
|
Throwable throwable = e;
|
||||||
|
if(throwable instanceof InvocationTargetException){
|
||||||
|
throwable = ((InvocationTargetException) throwable).getTargetException();
|
||||||
|
}
|
||||||
|
|
||||||
// 异常回调(只捕获业务代码导致的异常,而非反射导致的异常)
|
// 异常回调(只捕获业务代码导致的异常,而非反射导致的异常)
|
||||||
if (aspect.afterException(target, method, args, e.getTargetException())) {
|
if (aspect.afterException(target, method, args, throwable)) {
|
||||||
throw e;
|
throw throwable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user