隨心所欲代碼
outputStream不需要手動關(guān)閉怔檩,servlet容器在本次請求的生命周期末尾會自動關(guān)閉流,如果在Controller中手動關(guān)閉空猜,后續(xù)容器再使用到流的時候就報異常
老老實實绽慈,規(guī)規(guī)范范
Content-disposition:
決定瀏覽器是打開文件還是下載文件
Content-Type:
標(biāo)頭告訴客戶端實際返回的內(nèi)容的內(nèi)容類型。
-
application/octet-stream:
二進(jìn)制流辈毯,不知道下載文件類型坝疼,行為為下載,就算設(shè)置了Content-disposition
為inline谆沃,瀏覽器也還是會是下載的行為 - Controller中的[Get,Post]Mapping注解中有一個屬性
produces
可以指定內(nèi)容類型 -
application/pdf:
PDF文件 -
application/vnd.ms-excel:
EXCEL文件
org.springframework.http.MediaType
這個類中包含了絕大部分Content-Type