public abstract class BaseDaoImpl<T> implements BaseDao<T> {
protected Class<T> clazz;
public BaseDaoImpl() {
ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
clazz = (Class) pt.getActualTypeArguments()[0];
System.out.println("---> clazz = " + clazz);
}
public void save(T entity) {
getSession().save(entity);
}
public void delete(Long id) {
Object obj = getSession().get(clazz, id);
getSession().delete(obj);
}
获取子类穿过来的泛型
最新推荐文章于 2023-08-09 21:15:27 发布