Issue
I created an app using Spring and RestControllers. Now I would like to recreate the exact same controllers but using MVC controllers instead of Rest ones.
Is it just an annotation to change like going from @RestController
to @Controller
?
Is there something else to do?
Solution
@RestController
is an annotation with @ResponseBody
and @Controller
. If you want to return some data structure like JSON, you should use @ResponseBody
in controller method and @Controller in controller class. You can also only use @RestController
in controller class. If you want to return page like jsp or html, you should use @Controller
and InternalResourceViewResolver
.
Answered By - Vinlen