3
我想創建將發送到客戶端CSV文件的控制,我創建了一個控制器:編碼下載的文件在Spring
@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);
}
記錄儀顯示的是正確的字符串:
一些文本
但在下載文件還有另外一個
U29tZSB0ZXh0
我該如何解決這個問題?