public static Field getIdField(Object object) {
List<Field> fieldList = new ArrayList<>();
Field[] declaredFields = object.getClass().getDeclaredFields();
for (Field field : declaredFields) {
if (field.isAnnotationPresent(Id.class)) {
fieldList.add(field);
}
}
if (fieldList.size() == 0) {
throw new RuntimeException(object.getClass().getSimpleName() + "实体类必须有一个包含@Id的字段");
}
if (fieldList.size() > 1) {
throw new RuntimeException(object.getClass().getSimpleName() + "实体类必须有一个包含@Id的字段");
}
return fieldList.get(0);
}
EntityRefelectUtils.java 文件源码
java
阅读 46
收藏 0
点赞 0
评论 0
项目:FastSQL
作者:
评论列表
文章目录