这不起作用:[仅更改了 .map()]
return findTechnician.findWithUser()
.stream()
.map(this::toDTO)
.collect(Collectors.toSet());
Error:
Method threw 'java.lang.TypeNotPresentException' exception.
Type com.grupoaev.aevgestion.domain.entities.solicitudes.Tecnico not present
这是我的实际课程:
private static class TechniciansModel extends LoadableDetachableModel<Collection<TechnicianDatesDTO>> {
private static final long serialVersionUID = 1L;
@SpringBean
private FindTechnician findTechnician;
@SpringBean
private FindTechnicalUserAbsences findTechnicalUserAbsences;
public TechniciansModel() {
Injector.get().inject(this);
}
@Override
protected Collection<TechnicianDatesDTO> load() {
return findTechnician.findWithUser()
.stream()
.map(t->toDTO(t))
.collect(Collectors.toSet());
}
@NotNull
private TechnicianDatesDTO toDTO(Tecnico technician) {
String displayingName = technician.getUsuario().getName();
Set<Range<LocalDate>> invalidDates =
findTechnicalUserAbsences.findByTecnicoId(technician.getId())
.stream()
.map(absence -> new Range<>(toLocalDate(absence.getFechaInicio()),
toLocalDate(absence.getFechaFin())))
.collect(Collectors.toSet());
return new TechnicianDatesDTO(displayingName, invalidDates);
}
private LocalDate toLocalDate(Date date) {
return date != null ? date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null;
}
}
我想这是一个我不理解的深层Java工作方式问题,而且我可能离它还很远......
应该以相同的方式工作:
return findTechnician.findWithUser()
.stream()
.map(t->toDTO(t))
.collect(Collectors.toSet());
尝试如下:
return findTechnician.findWithUser()
.stream()
.map(TechniciansModel::toDTO)
.collect(Collectors.toSet());
:: 与类名一起使用,而不是由对象使用。