There are many return types are available for a controller method in Spring MVC, which is annotated by @RequestMappinginside the controller. Some of the popular ones are:
- String
- void
- View
- ModelAndView (Class)
- Model (Interface)
- Map
- HttpEntity or ResponseEntity
- HttpHeaders
Every return type has its specific use. For example, if you are using String, then it means that the Controller will just return the View Name and this view name will be resolved by ViewResolver.
If you don’t want to return any view name, mention return type void. If you want to set a view name as well as want to send a object, use ModelAndViewas a return type.