package demo;
public class searchbean {
private int id;
private String goodsname;
private double price;
public String fieldsdemo;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsname() {
return goodsname;
}
public void setGoodsname(String goodsname) {
this.goodsname = goodsname;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
用getDeclaredFields就能得到private 和public protend protected 的字段
如果用c.getFields();只能得到public类型的属性
Class c =Class.forName("demo.searchbean");
Field[] f =c.getDeclaredFields();
for (Field fd : f) {
System.out.println(fd.getName());
}