模拟一个数据层dao
- @Slf4j
- public class GenericDao {
-
-
- public
T queryOne(Class beanClass, String sql, Object... args) { - try {
- log.debug("进入数据库查询.....");
-
- Constructor
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