top of page
Writer's pictureDhruv Patel

Different ways to send data from spring based web application to UI

We can send data from controller to UI in multiple ways


  • ModelAndView

  • Model

  • @ResponseBody

1. ModelAndView

Whenever we are using ModelAndView at that time we are sending data to the view component in the form of the key and value pair.








2. Model

In this we are passing model as a parameter in the method which is annotated with mapping of the request and returning the view name as a string. We are setting data into the model object using method.








3. Response body

In the above two ways we are returning the view to the user but in this way, we are returning data directly. This is UI independent way. There is no presentation file. This method is sending direct response as data.


So, for this method we don’t need view resolver because we are not returning the view from the controller. We will see @RestController annotation it is @controller + @ResponseBody = @RestController.


Whenever we are going for distributed component at that time we are going to use @ResposeBody and making component distributed.





47 views0 comments

Recent Posts

See All

Comments


bottom of page