Answer the question
In order to leave comments, you need to log in
How to get the names of all fonts in the controller in Spring?
Good afternoon. You need to get the paths to all the fonts in the /resources folder in the controller and transfer them to the html template. There are no problems with the transfer, but I can not receive.
If you write the path C:\Users\home\Desktop\fonts\src\main\resources\assets\fonts\hello.otf, then everything works, but I would like the application to determine the path itself on the server.
Here is the structure
And as in the template include styles?
How do I get files now
@GetMapping
public String main(Map<String, Object> model) {
String path = "src/main/resources/assets/fonts";
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
....
Answer the question
In order to leave comments, you need to log in
You can use PathMatchingResourcePatternResolver :
ClassLoader classLoader = this.getClass().getClassLoader();
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(classLoader);
Resource[] resources = resolver.getResources("classpath*:assets/fonts/*") ;
for (Resource resource: resources){
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question