使用apache的BeanUtils封装数据

来源:互联网 发布:宁波加工中心编程招聘 编辑:程序博客网 时间:2024/04/29 17:06
package cn.lgs.apache.tools;


import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.locale.converters.DateLocaleConverter;


public class BeanUtilsTest {


public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
// TODO Auto-generated method stub
Map map = new HashMap<String, Object>();

map.put("username", "lgs");
map.put("password", "111111");
map.put("birthday", "1989-10-01");

Account man = new Account();

BeanUtils bean = new BeanUtils();
ConvertUtils.register(new DateLocaleConverter(), Date.class);
bean.populate(man, map);

System.out.println(man);
}


}
0 0