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;
    }

 

 
posted on 2020-12-02 21:52  oktokeep  阅读(1071)  评论(0编辑  收藏  举报