简单的缓存案例
模拟一个数据层dao
@Slf4j
public class GenericDao {
public <T> T queryOne(Class<T> beanClass, String sql, Object... args) {
try {
log.debug("进入数据库查询.....");
Constructor<T> constructor = beanClass.getDeclaredConstructor();
constructor.setAccessible(true);
T t = constructor.newInstance();
Field username = beanClass.getDeclaredField("name");
Field age = beanClass.getDeclaredField("age");
username.setAccessible(true);
age.setAccessible(true);
username.set(t, "xiaoming");
age.set(t, 32);
return t;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public int update(String sql, Object... args) {
return 1;
}
}
class Student {
private String name;
privat