|
@@ -11,7 +11,15 @@ import com.gxzc.zen.common.config.request.annotation.KVType
|
|
|
import com.gxzc.zen.common.config.request.annotation.ZenRequestTypes
|
|
|
import com.gxzc.zen.common.dto.RequestDto
|
|
|
import org.springframework.beans.factory.annotation.Autowired
|
|
|
+import org.springframework.core.io.InputStreamResource
|
|
|
+import org.springframework.core.io.Resource
|
|
|
+import org.springframework.http.HttpHeaders
|
|
|
+import org.springframework.http.MediaType
|
|
|
+import org.springframework.http.ResponseEntity
|
|
|
import org.springframework.web.bind.annotation.*
|
|
|
+import java.io.File
|
|
|
+import java.io.FileInputStream
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -63,4 +71,26 @@ class TestController : BaseController() {
|
|
|
fun test() {
|
|
|
println(1)
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/download")
|
|
|
+ @Login(action = Action.Skip)
|
|
|
+ fun download(param: String): ResponseEntity<Resource> {
|
|
|
+
|
|
|
+ // ...
|
|
|
+ val file = File("D:\\WorkSpace\\Zen\\zen.log")
|
|
|
+ val resource = InputStreamResource(FileInputStream(file))
|
|
|
+
|
|
|
+ val headers = HttpHeaders()
|
|
|
+ headers.add("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
+ headers.add("Pragma", "no-cache")
|
|
|
+ headers.add("Expires", "0")
|
|
|
+ headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=zen.log")
|
|
|
+
|
|
|
+
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .headers(headers)
|
|
|
+ .contentLength(file.length())
|
|
|
+ .contentType(MediaType.parseMediaType("application/octet-stream"))
|
|
|
+ .body(resource)
|
|
|
+ }
|
|
|
}
|