首页 > 解决方案 > 使用 REST 服务下载文件列表

问题描述

我是 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();
    }
}

有人可以告诉我如何修改此代码,以便我能够下载文件列表吗?

标签: javarestfile

解决方案


推荐阅读