beanutils设置参数和获取参数

public class Employee implements DynaBean  {

    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 Employee getEmployee(int index) {
        return new Employee();
    }
     //private Address address;
     public Address getAddress(String home) {
        return new Address();
    }

}

 

public class EmployeeTest {

//    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"));
//    }
    
//    public static void main(String[] args) throws Exception {
//        Employee employee=new Employee();
//        int index=3;
//        String emp="employee["+index+"]";
//        //PropertyUtils.setIndexedProperty(employee, num, new Object[]{1,2,3});
//        Employee e=(Employee) PropertyUtils.getIndexedProperty(employee, emp);
//        System.out.println(e);
//    }
    
//    public static void main(String[] args) throws Exception {
//        Employee employee=new Employee();
//        int index=3;
//        String emp="employee";
//        Employee e=(Employee) PropertyUtils.getIndexedProperty(employee, emp,index);
//        System.out.println(e);
//    }
    
//    public static void main(String[] args) throws Exception {
//        Employee employee=new Employee();
//        Address address=new Address();
//        PropertyUtils.setMappedProperty(employee, "address", "address", address);
//        //System.out.println(PropertyUtils.getMappedProperty(employee, "address()"));
//    }
    
//    public static void main(String[] args) throws Exception {
//        Employee emp=new Employee();
//        String city=(String) PropertyUtils.getNestedProperty(emp, "address(home).city");
//        System.out.println(city);
//    }
    
//    public static void main(String[] args) throws Exception {
//        Employee emp=new Employee();
//        String city=(String) PropertyUtils.getProperty(emp, "employee[3].address(home).city");
//        System.out.println(city);
//    }
    
//    public static void main(String[] args) {
//        DynaBean emp=new Employee();
//        System.out.println(emp.get("firstName"));
//        System.out.println(emp.get("address", "home"));
//        System.out.println(emp.get("emp", 3));
//    }
    
    public static void main(String[] args) throws Exception {
        DynaProperty[] pros=new DynaProperty[]{
                new DynaProperty("address",com.dan.entity.Address.class),
                new DynaProperty("employee",com.dan.entity.Employee[].class),
                new DynaProperty("firstName",String.class)
        };
        BasicDynaClass dynaBean=new BasicDynaClass("employee",null,pros);
        DynaBean dyna= dynaBean.newInstance();
        dyna.set("firstName", "李");
        System.out.println(dyna.get("firstName"));
    }

}

 

转载于:https://www.cnblogs.com/danmao/p/4053354.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值