javaBean使用BeanUtils操作(高新技术学习)

---------------------- ASP.Net+Unity开发.Net培训、期待与您交流! ----------------------

//定义一个javaBean

public class StudentBean {

private String name;
private int age;
private Boolean lb;
private double fen;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Boolean getLb() {
return lb;
}
public void setLb(Boolean lb) {
this.lb = lb;
}
public double getFen() {
return fen;
}
public void setFen(double fen) {
this.fen = fen;
}

}

//练习类

public class studentBeanTest {

public static void main(String[] args) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
StudentBean student=new StudentBean();
BeanUtils b=new BeanUtils();

//设置属性
b.setProperty(student,"name", "张三");
b.setProperty(student,"age", "12");
b.setProperty(student,"lb", "true");
b.setProperty(student,"fen", "10.23D");

//Map集合数据存放到javaBean中。
Map<String, String> map=new HashMap<String, String>();
map.put("name", "王二");
map.put("age", "112");
map.put("lb", "false");
map.put("fen", "1.02D");
b.populate(student, map);
System.out.println(b.getProperty(student, "name"));
System.out.println(b.getProperty(student, "age"));
System.out.println(b.getProperty(student, "lb"));
System.out.println(b.getProperty(student, "fen"));

//javaBean数据存放到Map集合中。
Map<String, String> map1=new HashMap<String, String>();
map1=b.describe(student);
Set<Entry<String, String>> entry =map1.entrySet();

//将javaBean数据存放到Map集合后,迭代打印map1集合里的数据,会多出来一个(class-----class com.tsh.text.StudentBean)键值对信息
for (Entry<String, String> entry2 : entry) {
System.out.println(entry2.getKey());
System.out.println(entry2.getValue());
}
}

}

---------------------- ASP.Net+Unity开发.Net培训、期待与您交流! ----------------------详细请查看: http://edu.csdn.net
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值