Can't open index page

Viewed 59
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.

2 Answers

Try this :

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

`I used this solution an it's work:

    @RequestMapping(value = {"", "/","/index"}, method = RequestMethod.GET)
    public String index()
    {
        return "index";
    }
Related