I'm the new Spring learner.i'm really confused what is the difference between two concepts:
- @ModelAttribute
- model.addAttribute
There are two user values โโbelow. What it is? Why should I use this? Thanks to everyone.
@RequestMapping(method = RequestMethod.GET) public String setupForm(ModelMap model) { model.addAttribute("user", new User()); return "editUser"; } @RequestMapping(method = RequestMethod.POST) public String processSubmit( @ModelAttribute("user") User user, BindingResult result, SessionStatus status) { userStorageDao.save(user); status.setComplete(); return "redirect:users.htm"; }
source share