public String getPkColumn(String className) { String pkColumn = null; try { Class clazz = Class.forName(className); Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { if(field.getAnnotation(Id.class) != null){ Annotation annotation = field.getAnnotation(Column.class); pkColumn = ((Column)annotation).name(); break; } } } catch (ClassNotFoundException e) { e.printStackTrace(); } finally { return pkColumn; } }
时间: 2024-11-13 10:08:11