如何使用映射器将 DTO 中的列表 <String> 设置为 DTO 中的字符串
how to use mapper for list<String> from DTO set to String from DTO
public class MessageRqDTO implements Serializable {
private Long id;
private String data;
private String device;
private String headers;
private Boolean isProcessed;
private String notification;
private String referenceCode;
private Boolean scheduled;
private Boolean transactional;
private Instant startFromTime;
private Instant expirationTime;
private List<String> identifiers = new ArrayList<>();
private UserTokenDTO userToken;
}
首先 dto 列出标识符
public class MessagetoMqDTO implements Serializable{
private Long id;
private String data;
private String device;
private String headers;
private Boolean isProcessed;
private String notification;
private String referenceCode;
private Boolean scheduled;
private Boolean transactional;
private Instant startFromTime;
private Instant expirationTime;
private String identifiers ;
private UserTokenDTO userToken;
private String clientToken;
}
第二个 DTO
使用这个
@Mapping(target = "messageDTO", source = "messageDTO")
MessagetoMqDTO toDto(MessageRqDTO m,String identifier,String clientToken);
错误:
java: Can't map property "String identifiers" to "List<String> identifiers". Consider to declare/implement a mapping method: "List<String> map(String value)".
将此方法添加到您的映射器接口:
default String mapIdentifiers(List<String> identifiers){
String identifiersSeparator = ",";
return identifiers.stream().collect(Collectors.joining(identifiersSeparator));
}
public class MessageRqDTO implements Serializable {
private Long id;
private String data;
private String device;
private String headers;
private Boolean isProcessed;
private String notification;
private String referenceCode;
private Boolean scheduled;
private Boolean transactional;
private Instant startFromTime;
private Instant expirationTime;
private List<String> identifiers = new ArrayList<>();
private UserTokenDTO userToken;
}
首先 dto 列出标识符
public class MessagetoMqDTO implements Serializable{
private Long id;
private String data;
private String device;
private String headers;
private Boolean isProcessed;
private String notification;
private String referenceCode;
private Boolean scheduled;
private Boolean transactional;
private Instant startFromTime;
private Instant expirationTime;
private String identifiers ;
private UserTokenDTO userToken;
private String clientToken;
}
第二个 DTO 使用这个
@Mapping(target = "messageDTO", source = "messageDTO")
MessagetoMqDTO toDto(MessageRqDTO m,String identifier,String clientToken);
错误:
java: Can't map property "String identifiers" to "List<String> identifiers". Consider to declare/implement a mapping method: "List<String> map(String value)".
将此方法添加到您的映射器接口:
default String mapIdentifiers(List<String> identifiers){
String identifiersSeparator = ",";
return identifiers.stream().collect(Collectors.joining(identifiersSeparator));
}