Rud*_*idt 3 spring spring-boot java-11
我想生成一个博客文章概述。为此,我想从 Spring Boot 存储其模板的资源文件夹中的模板文件夹内的文件夹中读取 html 文件。
我试过了,但它没有返回错误,但也没有列出任何文件。
去这里的路是什么?
谢谢
@Controller
public class Route {
@Autowired
private ResourceLoader resourceLoader;
@RequestMapping("/")
public String home() throws IOException {
final String path = "templates/blog";
final Resource res = resourceLoader.getResource("templates/blog");
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(res.getInputStream()))) {
reader.lines().forEachOrdered(System.out::println);
}
return "blog/a";
}
}
Run Code Online (Sandbox Code Playgroud)
@Controller
public class Route {
@Value("classpath:templates/blog/*")
private Resource[] resources;
@RequestMapping("/")
public String home() throws IOException {
for (final Resource res : resources) {
System.out.println(res.getFilename());
}
return "blog/a";
}
}
Run Code Online (Sandbox Code Playgroud)
对我做了伎俩。
| 归档时间: |
|
| 查看次数: |
5052 次 |
| 最近记录: |