public class Source1 { private String name; //srihari private List<String> city_names; //city_names.add("hyderabad-india") }public class Soruce2 { private String name; private String city_name; //hyderabad-india private List<String> technologies; //Arrays.asList("java","mapstruct") }public class Target { private String name; // Result: srihari private String city_names; // Result: hyderabad-india private String technologies; // Result: java, mapstruct}`列表只有一個值意味著 list.size()=1。如果 source1 名稱為空,則必須取自 source2。并且目標應該包含所有字段,即使這些字段在一個源中不可用
1 回答

米脂
TA貢獻1836條經驗 獲得超3個贊
嘗試:
@Mapper
public interface MyMapper{
// will map all other fields that you specify
@Mapping( target = "city_names", ignore = true )
@Mapping( target = "technologies", ignore = true )
Target map(Source1 s1, Soruce2 s2);
default map(Source1 s1, Soruce2 s2, @MappingTarget Target t) {
// do whatever you like with city_names and technologies
}
}
添加回答
舉報
0/150
提交
取消