Java类属性
Java类属性:
1)在JavaEE中,Java类的属性通过getter,setter 未定义:get(或set)方法,去除get(或set)后,
后字母小写即为Java类的属性
public String getName() { return name; } public void setName(String name) { this.name = name; }
2)而以前叫的的那个属性,即成员变量,称之为字段。
3)操作Java类的属性有一个工具包:Beanutil
①setProperty()
②getProperty()
//通过BeanUtils工具包对属性赋值 @Test public void test1() throws InvocationTargetException, IllegalAccessException { Object object = new Student(); System.out.println(object); BeanUtils.setProperty(object,"name","yang"); System.out.println(object); } //通过BeanUtils工具包对属性取值 @Test public void test2() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Object object = new Student(); System.out.println(object); BeanUtils.setProperty(object,"password","yang"); System.out.println(object); Object value = BeanUtils.getProperty(object,"password"); System.out.println(value); }