BeanUtils是Apache Commons下的成员,通过反射封装参数,给对象赋值。
主要用法:
BeanUtils.copyProperties(source, target);
Bug
因为BeanUtils在做Date转换的时候,如果Date为null它是没有办法做类型转换的,会抛一个异常
org.apache.commons.beanutils.ConversionException: No value specified for 'Date'
主要是因为BeanUtils里面不支持java.util.Date,但是它支持java.sql.Date也就是它的子类
解决:
PropertyUtils.copyProperties(dest, orig);
PropertyUtils和BeanUtils都是Apache Commons下的成员,但如果类型不同BeanUtils是会做转换的,而PropertyUtils则会直接抛异常的。