org.springframework.beans.BeanUtils属性赋值 Date类型处理转换为LocalDateTime, Date不能直接赋值给LocalDateTime
Date createTime = book.getCreateTime(); Date updateTime = book.getUpdateTime(); //属性值处理 BeanUtils.copyProperties(book, entity); entity.setCreateTime(LocalDateTimeUtil.dateToLocalDateTime(createTime)); entity.setUpdateTime(LocalDateTimeUtil.dateToLocalDateTime(updateTime));
LocalDateTimeUtil.java
public static LocalDateTime dateToLocalDateTime(Date date) { LocalDateTime localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); return localDate; }