-2

I'm trying to return to an HTML file from the Spring boot Controller but I am getting an error: Whitelabel Error Page This application has no explicit mapping for /error

My Controller:

@Controller
public class HomeController {

@RequestMapping ("/")
public ModelAndView homePage() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("homepage");
    return modelAndView;
}
}

If any one have solution please help me.

  • Have you searched the question before posting it? It's about how to serve static content: https://docs.spring.io/spring-boot/docs/1.1.x/reference/htmlsingle/#boot-features-spring-mvc-static-content – troy Jan 13 '21 at 03:58

1 Answers1

0

I think your controller is not able to find your homepage. I am not sure but please first check your pom.xml file to whether you have added Thymeleaf dependency ie.

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

And when you return to an HTML page from the controller it looks for the HTML page in the temples folder, So be sure that your homepage.html is within the templets folder and then you can return your page name as a string from your controller Like this:

@Controller
public class HomeController {

@RequestMapping ("/")
public String homePage() {
    return homepage;
}
}

Once try this it will work.