2
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Controller
public class IndexController
{
    @GetMapping("/")
    public String index() {
        //int i = 9/0;   error page test
        return "index";
    }
}

There is a wave line under the "index". And IDEA tells me that it cannot resolve MVC View 'index'. I have already put index page and error page under the templates directory, when I run it and it still shows me a whitelable error page. Surprisingly, it works(open a index page) when i use @RestController instead of @Controller, but still show me whitelabel error page when I want to open a 404 page and 500 page.

Yuxin Cui
  • 23
  • 2

2 Answers2

0

Try this :

 @GetMapping({"/index"})
public String index()
{
    return "index";
}
0

`I used this solution an it's work:

    @RequestMapping(value = {"", "/","/index"}, method = RequestMethod.GET)
    public String index()
    {
        return "index";
    }
bobikel
  • 16
  • 1
  • 6
  • It cause a circular view path. By the way, will my code work without Handller? – Yuxin Cui Aug 12 '20 at 17:30
  • if you have a circular view path you can look at this solution https://stackoverflow.com/a/60788855/13044044. – bobikel Aug 12 '20 at 17:53
  • you can use your code without handler but you need some parameters. you can see this https://stackoverflow.com/a/30193013/13044044 – bobikel Aug 12 '20 at 17:58
  • 1
    I just find that my code returns me a web page with a string 'index', but not the index page, what caused it doesn't returns me a webpage that I defined. – Yuxin Cui Aug 12 '20 at 18:01