@Data public class AVo { private Long endTime; private String name; private String id; }
@Data public class ABVo { private LocalDateTime endTime; private String name; private String id; }
AVo aVo = new AVo(); ABVo bVo = new ABVo(); aVo.setEndTime(1720141535793L); aVo.setName("李逵"); aVo.setId("sdd"); Long sourceEndTime = aVo.getEndTime(); LocalDateTime targetEndTime = sourceEndTime != null ? LocalDateTime.ofInstant(Instant.ofEpochMilli(sourceEndTime), ZoneId.systemDefault()) : null; bVo.setEndTime(targetEndTime);
//不好使,endTime类型不一致,直接导致java.lang.IllegalArgumentException: Can not set java.time.LocalDateTime field com.ctfo.platform.devplatformserver.
// service.impl.ABVo.endTime to java.lang.Long ,生产上导致了OOM
// BeanUtil.copyPropertiesByField(aVo, bVo);
// 此处为核心代码
CopyOptions copyOptions = CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true); BeanUtil.copyProperties(aVo, bVo,copyOptions);
System.out.println(bVo.getEndTime()); System.out.println(bVo.getName());
标签:lang,java,数据类型,private,aVo,Long,LocalDateTime,bVo From: https://www.cnblogs.com/GranceWang2014/p/18285281