Wie erreiche ich das?
Spring Web kann das automatisch Konvertieren Sie JSONs in meine benutzerdefinierten Objekte, sodass ich keinen String akzeptieren und ihn dann selbst analysieren muss. Kann Spring Web dasselbe für CSVs tun? Oder muss ich eine Datei tatsächlich akzeptieren und sie dann selbst manuell analysieren (wahrscheinlich mithilfe einer externen Bibliothek wie Apache Commons Csv)?
Code: Select all
// what I want to work but what apparently doesn't
@PostMapping(path = "/batch", consumes = "text/csv")
public ResponseEntity postSocksBatch(List socksRequestDtos) {
socksRequestDtos.forEach(socksService::save);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
Ich habe 415 Nicht unterstützter Medientyp erhalten
Code: Select all
@PostMapping(path = "/batch", consumes = "text/csv")
public ResponseEntity postSocksBatch(@RequestBody Object file) {
Code: Select all
curl --location 'http://localhost:8080/api/socks/batch' \
--header 'Content-Type: text/csv' \
--data-binary '@/C:/Users/nadch/OneDrive/Рабочий стол/socks.csv'


Versuch 2
500 Interner Serverfehler
Code: Select all
@PostMapping(path = "/batch", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity postSocksBatch(@RequestBody MultipartFile file) {
Code: Select all
curl --location 'http://localhost:8080/api/socks/batch' \
--header 'Content-Type: multipart/form-data' \
--data-binary '@/C:/Users/nadch/OneDrive/Рабочий стол/socks.csv'

Code: Select all
org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found