service正常返回byte[],HttpHeaders设置x-download不起作用仍是application/json.
晚上回家再验证。
ps:正常在response设置响应头和响应体就好,ResponesEntity应该就只是spring boot提供的构造响应体的东西。
update:
在家里并不能复现!
```
//@Controller
@RestController
public class TestController {
@GetMapping("/test/a")
// @ResponseBody
public ResponseEntity<byte[]> a() throws IOException {
Resource resource = new ClassPathResource("a.xlsx");
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment; filename=" + "fuck.xlsx");
headers.add("Last-Modified", new Date().toString());
InputStream inputStream = resource.getInputStream();
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
return ResponseEntity.ok().headers(headers).contentLength(bytes.length).contentType(MediaType.APPLICATION_OCTET_STREAM).body(bytes);
}
}
```