我正在尝试使用具有 Date (java.util.Date) 字段的 Mapstruct 的映射器将对象转换为具有 LocalDateTime 字段的对象。问题在于它映射的时间错误,因为在具有 LocalDateTime 字段的对象中它总是显示少 2 小时。
@Mapping(source = "createdDate", target = "createdLocalDateTime")
ObjectA toEntity(ObjectB);
Run Code Online (Sandbox Code Playgroud)
我认为问题在于自动实现:
if ( createdDate!= null ) {
objectA.createdLocalDateTime( LocalDateTime.ofInstant( createdDate.toInstant(), ZoneId.of( "UTC" ) ) );
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?谢谢!