0

I started to learn Spring and came onto @ModelAttribute annotation, which i can find real use for. Can someone give me a real example of it? Because as i understand (i'm just beginner so might be wrong), methods that are annoteded with @ModelAttribute add return value/object into Model before every request. I saw examples like :

@ModelAttribute
List<Person> addList()
{
    return personRepository.findAll();
}

however usually Controllers are responsible for many other actions like adding or removing existing element (where we don't need that list). So once again can can someone give me a real example? Or maybe i misunderstand some things about that annotation.

peter Schiza
  • 387
  • 7
  • 23

1 Answers1

0

@ModelAttribute is a multipurpose annotation. We can use it to share any data to the view page.we can use it to take parameter of handler method of controller class as command class. We can use it for request wrapping.Also to return value of handler method as ModelAttribute and etc

amit
  • 25
  • 8