public List<String> getHtml() throws Exception {
List<String> nameList = new ArrayList<>();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath:templates/*.html");
for (Resource resource : resources) {
String filename = resource.getFilename();
nameList.add(filename);
}
return nameList;
}
打包后也可以获取到, windows和linux平台都可以获取到
这段代码在打包后仍能运行,无论在Windows还是Linux环境下,它使用PathMatchingResourcePatternResolver从`classpath:templates/*.html`路径下获取所有HTML文件,并将文件名添加到列表中返回。
1589

被折叠的 条评论
为什么被折叠?



