@SuppressWarnings("unchecked") private static final <T extends BaseModel> T getProxy(T model, final boolean createdByInstance) { if (ClassUtils.isProxy(model.getClass())) { return model; } final BaseModelInterceptor interceptor = new BaseModelInterceptor(model, createdByInstance); Enhancer enhancer = new Enhancer(); // 设置最后生成的代理类的父类 enhancer.setSuperclass(model.getClass()); // 设置切面回调 enhancer.setCallback(interceptor); final T proxy = (T) enhancer.create(); return proxy; }
public static final <T extends BaseModel> T getProxy(Class<T> clazz) { final T model = ClassUtils.newInstance(clazz); return getProxy(model, false); }