G
G
GizzaProger2019-08-27 10:51:33
Java
GizzaProger, 2019-08-27 10:51:33

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
5d64e145249d5806032995.png
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

1 answer(s)
S
Sergey Gornostaev, 2019-08-27
@GizzaProger

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 question

Ask a Question

731 491 924 answers to any question