本文整理匯總了Java中org.springframework.http.ResponseEntity.BodyBuilder方法的典型用法代碼示例。如果您正苦於以下問題:Java ResponseEntity.BodyBuilder方法的具體用法?Java ResponseEntity.BodyBuilder怎麽用?Java ResponseEntity.BodyBuilder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.http.ResponseEntity
的用法示例。
在下文中一共展示了ResponseEntity.BodyBuilder方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serveFile
import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
@GetMapping("/files/{filename:.+}")
@ResponseBody
public ResponseEntity<Resource> serveFile(@PathVariable String filename) {
Resource file = storageService.loadAsResource(filename);
String mediaType;
ResponseEntity.BodyBuilder ok = ResponseEntity.ok();
if (filename.endsWith("xlsx")) {
ok = ok.header(HttpHeaders.CONTENT_TYPE,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename);
} else if (filename.endsWith("csv")) {
ok = ok.header(HttpHeaders.CONTENT_TYPE, "text/csv");
} else {
ok = ok.header(HttpHeaders.CONTENT_TYPE, "application/json");
}
return ok.body(file);
}
示例2: buildStatus
import org.springframework.http.ResponseEntity; //導入方法依賴的package包/類
private static ResponseEntity.BodyBuilder buildStatus ( int status ) {
return ResponseEntity.status( status );
}