How to return an HTML page from a RESTful controller in Spring Boot?

When using @RestController like this:

@RestController
public class HomeController {

    @RequestMapping("https://stackoverflow.com/")
    public String welcome() {
        return "login";
    }
}

This is the same as you do like this in a normal controller:

@Controller
public class HomeController {

    @RequestMapping("https://stackoverflow.com/")
    @ResponseBody
    public String welcome() {
        return "login";
    }
}

Using @ResponseBody returns return "login"; as a String object. Any object you return will be attached as payload in the HTTP body as JSON.

This is why you are getting just login in the response.

Leave a Comment

tech