我想使用spring boot创建一个restful服务,它将下载位于服务器http:8080/someurl/{fileid}
的jar。我该怎么办?
答案 0 :(得分:13)
@RequestMapping(value = "/files/{fileID}", method = RequestMethod.GET)
public void getFile(
@PathVariable("fileID") String fileName,
HttpServletResponse response) throws IOException {
String src= DestLocation.concat("\\"+fileName+".jar");
InputStream is = new FileInputStream(src);
IOUtils.copy(is, response.getOutputStream());
response.flushBuffer();
}