Home » Java » java – Spring-boot restapi page call-Exceptionshub

java – Spring-boot restapi page call-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I got a simple spring boot application. I am trying load the html file through a rest controller. Below is my folder structure. I am unable to load test.html (just as helloworld code inside it)

enter image description here

@RequestMapping("/show1")
public ModelAndView showpage1() {
    System.out.println("## show1");
    ModelAndView modelAndView = new ModelAndView();
     modelAndView.setViewName("test");
     return modelAndView;
}

My test.html content

<h1> hello World </h1>
How to&Answers:

Try doing this :

 @RequestMapping("/show1")
            public String showpage1() {
                return "test";
            } 

where test.html is your page

Answer:

You just need to return the string with the name of the view.

@RequestMapping("/showpage")
public String showpage1() {
      return "test";
}