在后台生成了docx文件,保存在相对路径。
然后前台点击文件列表来获取相对路径文件目录下的所有文件,以列表的形式,展示。
但是每次生成了文件无法下载,必须重启项目之后,才能下载。
直接生成,直接下载,浏览器会报找不到文件的错误,但是重启项目之后,就可以下载了。
前台代码:
<table class="table table-striped table-hover"> <tr> <% for (path in FilePaths){ %> <a href="/static/docx/major/${path.key}" download="${path.key}">${path.key}</a> <% } %> </tr> </table>
后台代码:
@Override
public Map getFileList() {
Map<String,String> map = new HashMap(); String srcPath="src/main/webapp/static/docx/major"; File file = new File(srcPath); String[] files = file.list(); for (String str:files){ map.put(str,srcPath+"/"+str); } return map; }
慕妹3242003
鸿蒙传说
温温酱
拉风的咖菲猫
相关分类