我是新來的java。我想添加一個元素到列表中。如何添加元素到模型類型列表
List<RequestAttachmentDTO> attachments
RequestAttachmentDTO類是在這裏,
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;
}
}
這是我試圖添加,
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");
它不接受它。
PS: - 文件item
被視爲從multipart/form-data
編碼的JSP頁面上傳。
你能幫我添加元素到這個列表。謝謝。
「字符串fiileName =」 ...有沒有在你的代碼一個錯字? – JonyD