我为ModelMapper创建了自定义转换器,以将String转换为UUID,但是使用这种方法,我需要为所有类编写很多重复的代码。我想使以下方法成为通用方法,该方法将2类作为输入并配置特定字段的映射,以便可以对所有不同的类使用相同的方法。
PropertyMap<JobDTO.JobFunctionDTO, JobFunction> jobFunction(Converter<String, UUID> convertStringToUUID) {
return new PropertyMap<JobDTO.JobFunctionDTO, JobFunction>()
{
protected void configure()
{
using(convertStringToUUID).map(source.getId()).setId(null);
}
};
我尝试使用下面的代码将此函数转换为泛型,但遇到编译问题:无法解析方法'getId()'
PropertyMap<Source, Destination> jobFunction(Converter<String, UUID> convertStringToUUID) {
return new PropertyMap<Source, Destination>() {
protected void configure() {
using(convertStringToUUID).map(source.getId()).setId(null);
}
};
}
有人可以帮助我将上述方法转换为通用方法吗?