0

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>
rah
  • 67
  • 1
  • 8
  • Would you update your answer with POM.xml as well – Swarit Agarwal Feb 18 '20 at 05:04
  • https://stackoverflow.com/a/40766349/4214241 . You probably are missing the right dependency – R.G Feb 18 '20 at 05:32
  • please go throw the following reference. [stackoverflow.com/questions/38221461](https://stackoverflow.com/questions/38221461/how-to-make-an-html-file-appear-on-localhost-with-spring-boot) – Ranjith Bokkala Feb 18 '20 at 05:41
  • What is the template engine you are using? It will not work if you are not adding Template engine dependency. – Confuser Feb 18 '20 at 06:30

2 Answers2

0

Try doing this :

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

where test.html is your page

Adya
  • 1,084
  • 9
  • 17
  • Oh sorry you have added /show1 in your RequestMapping, so pls check the edited answer. – Adya Feb 18 '20 at 05:12
0

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

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