I am a newbie with Spring boot. I am trying to return my index page in the controller but I am not able to. Its just returning the word index in the output. Here's my code:
Controller class:
@RestController
public class IMEIController {
@Autowired
private IValidateIMEI iValidateIMEI;
@GetMapping("/")
public String home() {
return "index";
}
}
Application.properties file
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
Output:
CodePudding user response:
The issue is with @RestController
. Use @Controller
annotation instead.
@RestController
is use to create RESTful web services.
Here some articles if you need to know more.
CodePudding user response:
Spring boot does not work directly with JSPs. You will have to add tomcat Jasper embedded dependency to get it working.
https://www.baeldung.com/spring-boot-jsp
Also change @RestController to @controller.
And if you want to develop Rest JSP in the same controller then use @Controller on class level and add @ResponseBody for the rest API methods which will return response in the body instead of returning a JSP page.