gpt4 book ai didi

java - 如何查找实体类中没有属性

转载 作者:行者123 更新时间:2023-12-02 04:59:04 26 4
gpt4 key购买 nike

 public int getColumnCount() {
return getClass().getDeclaredFields().length;
}
this is the code which return no of attributes of same class,but not anaother class

In my service class,I want to know the number of attributes of a particular entity class.

I have tried a method,which tells the no of attributes present in the same class.But i want to know attributes of another class.

您能帮我达到要求吗?

最佳答案

Thanks a lot jonK,it worked helped me.

here is the code.
public int getAttributes() {
EmployeeDO employeeDo=new EmployeeDO();
Class<?> e=employeeDo.getClass();
return getAllAttributes(e);
}

private int getAllAttributes(Class<?> entityClass) {

return entityClass.getDeclaredFields().length;
}

关于java - 如何查找实体类中没有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56395182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com