首页 > 代码库 > beanutils通过SimpleProperty使用get或set方法赋值

beanutils通过SimpleProperty使用get或set方法赋值

public class Employee {

    private String  firstName;
    private String lastName;
    public Employee() {
    } ;  
    
     public String getFirstName() {
        return firstName;
    }
     public void setFirstName(String firstName) {
         this.firstName=firstName;
     }
     public String getLastName() {
        return lastName;
    }
     public void setLastName(String lastName){
         this.lastName=lastName;
     }
     private Date hireDate;
     public Date getHireDate(){
         return hireDate;
     }
     public void setHireDate(Date hireDate){
         this.hireDate=hireDate;
     }
     private boolean manager;
     public boolean isManager(){
         return manager;
     }
     public void setManager(boolean manager){
         this.manager=manager;
     }
     public String getFullName(){
         return lastName+firstName;
     }
}

 

public static void main(String[] args) throws Exception{
        Employee employee=new Employee();
        PropertyUtils.setSimpleProperty(employee, "firstName", "李");
        PropertyUtils.setSimpleProperty(employee, "lastName", "旭丹");
        System.out.println(PropertyUtils.getSimpleProperty(employee, "firstName")+"-"+PropertyUtils.getSimpleProperty(employee, "lastName"));
    }

beanutils通过SimpleProperty使用get或set方法赋值