EntityRefelectUtils.java 文件源码

java
阅读 46 收藏 0 点赞 0 评论 0

项目:FastSQL 作者:
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);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号