beanutilsexample2.java

来自「用java编写的程序」· Java 代码 · 共 36 行

JAVA
36
字号
package webbook.beanutils.example;

import java.util.GregorianCalendar;
import org.apache.commons.beanutils.LazyDynaBean;
import org.apache.commons.beanutils.BeanUtils;

public class BeanUtilsExample2 {

	public static void main(String args[]) throws Exception {

		LazyDynaBean address = new LazyDynaBean();
		address.set("country", "中国");
		address.set("city", "北京");
		address.set("postCode", "100120");
		address.set("addr", "天安门北大街888号");

		LazyDynaBean profile = new LazyDynaBean();
		profile.set("phone", "home", "11011011");
		profile.set("phone", "office", "82826905");
		profile.set("email", "web@v512.com");
		profile.set("address", 0, address);
		profile.set("birthDate", new GregorianCalendar(1900, 2, 5).getTime());

		LazyDynaBean user = new LazyDynaBean();
		user.set("userId", new Long(8888888));
		user.set("username", "刘伟");
		user.set("password", "ingodwetrust");
		user.set("profile", profile);

		System.out.println(BeanUtils.getProperty(user, "username"));
		System.out.println(BeanUtils.getProperty(user, "profile.birthDate"));
		System.out.println(BeanUtils.getProperty(user, "profile.address[0].addr"));
		System.out.println(BeanUtils.getProperty(user, "profile.phone(office)"));
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?