top of page

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.


ree

ree

ree

ree

ree


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.


ree

ree

ree

ree


ree

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.


ree

ree


 
 
 

Recent Posts

See All

Comments


MiIT Logo

Company

Contact Us

905-487-4880 

5160 Explorer Dr #34, Mississauga,ON L4W 4T7

929-743-3199

4466 Buttonwood Ln Lilburn, GA 30047

262 Chapman Rd, STE 240 Newark DE 19702

Stay up to date on the latest from MiIT

  • Instagram
  • Facebook
  • http://linkedin.com/company/miittechnologies/about/
  • Whatsapp

© All Content MiIT Technologies Inc.2019 - 2025. All rights reserved.

bottom of page