在对象属性拷贝过程中,可能会出现各种异常(如:类型转换异常、日期解析异常等),BeanUtils统一抛出BeanPropertyCopyException,用户根据需要使用即可。
BeanUtils
BeanPropertyCopyException
class Foo { Date date; } class FooDto { @Mapping(datePattern="yyyy-MM-dd") String date = "2018-10"; } try { Foo foo = BeanUtils.copyProperties(new FooDto(), Foo.class); } catch (BeanPropertyCopyException e) { System.out.println(e.getMessage()) // "属性:date拷贝时发生异常" System.out.println(e.getPropertyName()) // "date" System.out.println(e.getSourceObject()) // FooDto(date=2018-10) }
Last updated 6 years ago