使用 REST 服务下载文件列表

时间:2021-07-06 12:28:21

标签: java rest file

我是 Java 新手,目前正在尝试下载文件列表。我以此代码为基础来下载单个文件并且它正在工作。

package com.java2novice.restful;
 
import java.io.File;
 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
 
@Path("/download")
public class RestDownloadService {
 
    @GET
    @Path("/service-record")
    @Produces("application/pdf")
    public Response getFile() {
  
        File file = new File("C:\java2novice\employee_1415.pdf");
  
        ResponseBuilder response = Response.ok((Object) file);
        response.header("Content-Disposition",
            "attachment; filename=\"employee_1415.pdf\"");
        return response.build();
    }
}

谁能告诉我如何修改此代码以便我能够下载文件列表?

0 个答案:

没有答案
相关问题