java理解Spring引导中的@ModelAttribute和@RequestMapping
代码示例取自此处:https://www.baeldung.com/spring-mvc-and-the-modelattribute-annotation
以代码为例:
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
public String submit(
@ModelAttribute("employee") Employee employee,
BindingResult result, ModelMap model) {
if (result.hasErrors()) {
return "error";
}
model.addAttribute("name", employee.getName());
model.addAttribute("id", employee.getId());
employeeMap.put(employee.getId(), employee);
return "employeeView";
}
我知道@RequestMapping
只是将端点映射到此方法,但我不了解的是:
调用方法时,方法参数“来自”哪里?我不知道
ModelMap
来自哪里它如何知道
@ModelAttribute("employee")
是什么?这是来自View
(HTML),对吗Model
到底是什么?它只是<String, Object>
的映射类型吗?这个Model
的寿命是多少
共 (0) 个答案