Ich mag einen Controller erstellen, die an dem Client eine CSV-Datei gesendet werden, und ich geschaffen, um den nächsten Controller:Encoding für heruntergeladene Dateien im Frühjahr
@ResponseStatus(value = HttpStatus.OK)
@RequestMapping(value = "/csv", method = RequestMethod.GET)
public ResponseEntity downloadCsvAllInvoiceTransactionsByFilter(
@PageableDefault(direction = DESC, sort = "invoiceDate", size = 30) Pageable pageRequest) throws IOException {
String someVariable = "Some text";
byte[] out = someVariable.getBytes(Charset.forName("UTF-8"));
HttpHeaders responseHeaders = new HttpHeaders();
LOGGER.info(new String(out));
responseHeaders.add("content-disposition", "attachment; filename=transactions.csv");
responseHeaders.add("Content-Type","text/csv; charset=utf-8");
return new ResponseEntity<>(out,responseHeaders,HttpStatus.OK);
}
Logger ist die richtige Zeichenfolge anzeigt:
Einige Text
aber in heruntergeladenen Datei gibt es eine andere
U29tZSB0ZXh0
Wie kann ich dieses Problem beheben?