Spring boot Whitelabel Error Page

clipboard.png

clipboard.png

did not find the error why it is always 404, is the directory wrong? There is no problem with rendering without templates with @ ResController, but not with @ Controller
Whitelabel Error Page
This application has no explicit mapping for / error, so you are seeing this as a fallback.

Wed May 09 18:40:48 CST 2018
There was an unexpected error (type=Not Found, status=404).
No message available

Mar.10,2021

as a normal Controller:

@RequestMapping(value="/index")
public String hello(Model model) {
  model.addAttribute("somename", "Hello World!");  
  return "hello"
}

//

@RequestMapping(value="/index")
public ModelAndView hello() {
    ModelAndView mav = new ModelAndView();
    mav.setViewName("hello");
    mav.addObject("somename", "Hello World!");
    return mav;
}

means to return the name of a view called hello, you need to have the corresponding template (hello.jsp or hello.ftl or whatever)
this is different from RestController, the RestController modified class is to directly return the string as the content, and does not need a template.

if you just want to return a string, you can also use the @ ResponseBody annotation:

@RequestMapping(value="/index")
@ResponseBody
public String hello(Model model) {
  model.addAttribute("somename", "Hello World!");  
  return "hello"
}
Menu