尝试使用spring的Mapper注释功能时,我遇到了一些困难。我想使用映射器来映射java中的Map对象,如下所示:
HostCounters:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HostsCounters {
private Map<String,Map<String,Long>> hostsList;
}
映射器:
@Mapper(componentModel = "spring")
public interface ResponseMapper {
GeneralResponse toResponse(SevCount sevCount, HostsCounters hostsList, List<RegDAO> Reg);
}
一般响应:
@Data
@NoArgsConstructor
public class GeneralResponse {
private List<RegDAO> Reg;
private HostsCounters hostsList;
private SevCount sevCount;
}
错误:
无法映射属性
“ java.util.Map>
hostsList“到” HostsCounters hostsList“。考虑到
声明/实现映射方法
最佳答案
只需使用:
@Mapping(source = "hostsList", target = "hostsList")
GeneralResponse toResponse(SevCount sevCount, HostsCounters hostsList, List<RegDAO> Reg);
但我强烈建议您摆脱具有不同含义的相同名称:
HostsCounters hostsList -> HostsCounters hostsLists
关于java - 使用Spring Mapper映射Map对象-Java,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55590739/