Skip to content Skip to sidebar Skip to footer

How To Make An Html-file Appear On Localhost With Spring Boot?

I am using Spring Boot and have an html-file 'index.html', and I have a class 'Functions'. Basically, what I want to happen is that when the functions-class is run, and when I go t

Solution 1:

First of all, put the index.html template file in src/main/resources/templates instead of in src/main/resources/static.

Your class Functions must be a Spring MVC controller; you can make it a controller by adding the @Controller annotation. Return the name of the template in the getHomepage() method:

@Controller
public class Functions {
    @RequestMapping("/")
    public String getHomepage() {
        return "index";
    }
}

This is all basic Spring Web MVC; see a tutorial like this Serving Web Content guide on the Spring website and the reference documentation.


Post a Comment for "How To Make An Html-file Appear On Localhost With Spring Boot?"