【发布时间】:2019-12-12 12:04:54
【问题描述】:
我有 Spring Boot 应用程序,其实现包含具有以下功能的方法。该实现使用 2 个 DTO 来绑定数据。有没有合适的方法可以将值从 JAY 传递到 '10.00' 硬编码的值?我对 'this::convertProfileToProfileCreditDTO' 有主要问题,是否可以在此表达式中传递参数?
我已经使用Java DTO Object search mechanism? 进行启发
如果我尝试在以下代码中添加参数 this::convertProfileToProfileCreditDTO 抱怨返回类型错误
convertProfileToProfileCreditDTO(final Profile theProfile, Double JAY)
实施
@Override
public Double testThisParam(Double profileCredit) {
Double JAY = profileCredit;
log.error(String.valueOf(JAY));
return JAY;
}
@Override
public Page<ProfileCreditDTO> findProfileBySelectedParameters(String username, Pageable pageable) {
Page<Profile> searchData= profileRepository.findByAllParameters(username, pageable);
Page<ProfileCreditDTO> searchProfileData=null;
if(searchData != null)
searchProfileData=searchData.map(this::convertProfileToProfileCreditDTO);
return searchProfileData;
}
public ProfileCreditDTO convertProfileToProfileCreditDTO(final Profile theProfile ){
if(theProfile == null)
return null;
ProfileCreditDTO theDTO= new ProfileCreditDTO();
theDTO.setProfile(theProfile);
CreditDTO theCreditDto = profileCreditClient.findClientByProfileId(theProfile.getId(), 10.00);
if(theCreditDto != null )
theDTO.setCredit(theCreditDto);
else {
return null;
}
return theDTO;
}
【问题讨论】:
-
您可以使用 lambda 表达式并传递您想要传递的任何参数。像- map(profile -> convertProfileToProfileCreditDTO(profile, otherParameters).
标签: java spring microservices dto