Download the file with spring mvc ResponseEntity < byte [] >. The contents of the file are garbled.

backend code:

clipboard.png

,reponseheader,ResponseEntiry;

:

clipboard.png
;

,

clipboard.png

a.txt,:
:aaaa
:"YWFhYQ=="

springrequestMappingHandler:

clipboard.png

:

clipboard.png

ask for advice, how to solve it? do you want to change the configuration of handlermapping? I have tried to use ByteArrayHttpMessageConverter to swipe data to the browser. It still seems to be garbled

.
Mar.19,2021

has been solved. First, add application/octet-stream support stream format download to the support types of byteArrayHttpMessageConverter. Secondly, add @ RequestMapping (value= "/ downLoadTemplate", produces= "application/octet-stream;charset=UTF-8")
to the method. The main purpose is to let spring know the output format of the method, so that spring knows which messageConvert object to output content. The writeWithMessageConverters source code of abstractMessageConverterMethodProcessor involved is as follows:

clipboard.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4c82b-4346e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4c82b-4346e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?