Ich bin neu in Java. Ich möchte ein Element zu einer Liste hinzufügen.Wie füge ich Elemente zu einer Liste mit Modelltyp
List<RequestAttachmentDTO> attachments
RequestAttachmentDTO Klasse ist hier,
public class RequestAttachmentDTO {
byte[] contentStream;
String fileName;
String contentType;
String contentTransferEncoding;
public RequestAttachmentDTO(byte[] contentStream, String fileName, String contentType) {
this.contentStream = contentStream;
this.fileName = fileName;
this.contentType = contentType;
}
public RequestAttachmentDTO(byte[] contentStream, String fileName, String contentType,String contentTransferEncoding) {
this.contentStream = contentStream;
this.fileName = fileName;
this.contentType = contentType;
this.contentTransferEncoding=contentTransferEncoding;
}
public String getFileName() {
return fileName;
}
public String getContentType() {
return contentType;
}
public byte[] getContentStream() {
return contentStream;
}
public String getContentTransferEncoding() {
return contentTransferEncoding;
}
}
Dies ist, wie ich hinzufügen wollte,
String fieldName = item.getFieldName();
String fiileName = FilenameUtils.getName(item.getName());
fileContent = item.getInputStream();
Path path = Paths.get("/data/uploads/form_urlencoded_simple_decoded_body.txt");
byte[] data = Files.readAllBytes(path);
List<RequestAttachmentDTO> attachments = new ArrayList<>();
attachments.add(data,fieldName,"application/x-www-form-urlencoded");
Es akzeptiert es nicht.
PS: - Die Datei item
wird als Upload von einer JSP-Seite in multipart/form-data
Codierung übernommen.
Können Sie mir helfen, Elemente zu dieser Liste hinzuzufügen. Vielen Dank.
"String fiileName =" ... zu
attachments.add(new RequestAttachmentDTO(data,fieldName,"application/x-www-form-urlencoded"));
ändert, ist es ein Tippfehler in Ihrem Code? – JonyD