1. 程式人生 >實用技巧 >其它 >實習總結(第四天)

實習總結(第四天)


1、ResponseEntity

ResponseEntity可以作為controller的返回值,比如對於一個處理下載二進位制檔案的介面。ResponseEntity繼承了HttpEntity類,HttpEntity代表一個http請求或者響應實體,其內部有兩個成員變數:header及body,代表http請求或響應的header及body,其中的body是泛化的。

參考: (31條訊息) 【SpringMVC(十三)】ResponseEntity 使用 及 原理_絕世好阿狸的部落格-CSDN部落格_responseentity

2、java.nio.file.Path;

Path例項包含了指定檔案或目錄位置的資訊,在例項化Path類時,需要指定一個或多個目錄或檔名。

Path filePath = Paths.get(ConstValue.ROOT_PATH + "data/click_script/click.py");
//通過指定的路徑獲取資源 Resource resource
= new UrlResource(filePath.toUri());

3、Resource表示資源的介面,其具體實現

詳細 org.springframework.core.io.Resource介面原始碼分析_javaPie的部落格-CSDN部落格_org.springframework.core.io.resource

4、request.getServletContext().getMimeType

getServletContext代表整個web應用,可以和程式的容器(伺服器)來通訊

MIME型別:在網際網路通訊過程中定義的一種檔案資料型別

 contentType = request.getServletContext().getMimeType(resource.getFile().getAbsolutePath());//根據路徑獲取資源的型別

5.

表示擷取這個檔名的字尾,如aaa.txt,執行完之後得到suffix=txt

String suffix = Objects.requireNonNull(file.getOriginalFilename()).substring(file.getOriginalFilename().lastIndexOf("."));

6、

@PostMapping("/dataset/upload")
public Result<String> uploadDataset(