java文件下载 rest

/**
* 返回文件二进制
*
*/
@GET
@Path("/excel")
@Produces("application/vnd.ms-excel; charset=UTF-8")
@ModuleSecurityAuth(moduleId=ModuleId.MONITOR_REPORT ,privilegeOperation=PrivilegeOperation.READ)
public Response download(final @QueryParam("path") String path) throws IOException {
File file = new File("/macc/excel/"+path);
    //解决文件名乱码

      String pathTmp = java.net.URLEncoder.encode(path, "UTF-8");


        ResponseBuilder response = Response.ok((Object) file);
String header = "attachment; filename=" + pathTmp;
response.header("Content-Disposition",
header);
return response.build();
}
上一篇:从零开始搭建vue开发环境及构建vue项目


下一篇:Java学习、面试、求职、干货资源精品合集