What is @ModelAttribute in Spring MVC?

后端 未结 13 1129
一个人的身影
一个人的身影 2020-11-22 08:43

What is the purpose and usage of @ModelAttribute in Spring MVC?

13条回答
  •  生来不讨喜
    2020-11-22 09:46

    This is used for data binding purposes in Spring MVC. Let you have a jsp having a form element in it e.g

    on JSP

    (Spring Form method, Simple form element can also be used)

    On Controller Side

    @RequestMapping(value = "/test-example", method = RequestMethod.POST)
    public ModelAndView testExample(@ModelAttribute("testModelAttribute") TestModel testModel, Map map,...) {
    
    }
    

    Now when you will submit the form the form fields values will be available to you.

提交回复
热议问题