有没有办法在百万富翁中使用下载 attrribute,因为我无法通过html5下载文件。我试图从后端下载文件,它工作正常,但无法通过前端这样做。任何建议都会有所帮助......
<td th:switch="${xraydata.xrayResult}">
<span th:case="2"><a href="" th:href="@{/download/csv}">Abnormal but eligible for sputum</a></span>
<span th:case="1"><a th:href="${path}" target="_blank" th:attr="download">Normal</a></span>
<span th:case="3"><a th:href="@{/download/csv}" download>Abnormal but uneligible for sputum</a></span>
</td>
我在后端尝试了 th:case =“3”的代码:
@RequestMapping(value="/download/csv",method=RequestMethod.GET)
public void downloadFile(HttpServletResponse response) throws IOException {
System.out.println("the participants id is");
String FILE_PATH="C:/java/020.dcm";
final String APPLICATION_PDF = "020/dcm";
File file = getFile(FILE_PATH);
InputStream in = new FileInputStream(file);
response.setContentType(APPLICATION_PDF);
response.setHeader("Content-Disposition", "attachment; filename=" +
file.getName());
response.setHeader("Content-Length", String.valueOf(file.length()));
FileCopyUtils.copy(in, response.getOutputStream());
}