@ModelAttribute的使用以及相关注解的使用

文章内容来自于:https://blog.csdn.net/pange1991/article/details/48022961,作者:潘健男
文章主要用于自己学习SpringBoot,方便以后的查询

  • @ModelAttribute注解在方法上时,在进入@RequestMapping方法前,会先执行@ModelAttribute注解的方法
  • @ModelAttribute与@RequestMapping同时注解在一个方法上时,如:
@RequestMapping("/test")  
@ModelAttribute(value="pojo")  
public String test(){  
    return "modelTest";  
}  

该方法会在请求页面中传递attribute("pojo","modelTest")

  • @ModelAttribute注解在参数前,与@RequestParam类似

    @RequestParam绑定简单类型对象,如public void test(@RequestParam String key)

    @ModelAttribute绑定复杂类型对象,如public void test(@ModelAttribute User user)

  • @PathVariable、@RequestBody、@RequestHeader、@CookieValue、@SessionAttribute

    参照原文章博主的博客:https://blog.csdn.net/pange1991/article/details/48022961

猜你喜欢

转载自blog.csdn.net/chimmhuang/article/details/80460148