前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringMVC 之 ModelAndView和ModelAttribute的使用

SpringMVC 之 ModelAndView和ModelAttribute的使用

作者头像
冷冷
发布2018-02-08 11:16:05
9190
发布2018-02-08 11:16:05
举报
文章被收录于专栏:冷冷冷冷

ModelAndView解释 :

This class merely holds both to make it possible for a controller to return both model and view in a single return value.

这类控制器可以同时返回视图和模型数据.

ModelAndView使用:

ModelAndView()Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments.

ModelAndView(String viewName)Convenient constructor when there is no model data to expose.

ModelAndView(String viewName,Map<String,?> model)Creates new ModelAndView given a view name and a model.

ModelAndView(String viewName,String modelName, Object modelObject)Convenient constructor to take a single model object.

ModelAndView(View view)Convenient constructor when there is no model data to expose.

ModelAndView(View view,Map<String,?> model)Creates new ModelAndView given a View object and a model.

ModelAndView(View view,String modelName,Object modelObject)Convenient constructor to take a single model object.

ModelAttribute的使用:

在方法定义上使用 @ModelAttribute 注解:     Spring MVC在调用目标处理方法前,会在每个目标方法前,先逐个调用在方法级上标注了@ModelAttribute 的方法。 在方法的入参前使用 @ModelAttribute 注解:

    流程:1.执行@ModelAttribute注解的方法: 从数据库取出相关对象,自动把对象放到request的map中

            2.SpringMvc 从map中取出相关对象,并把前台相关的表单属性赋值给这个对象

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ModelAndView解释 :
  • ModelAndView使用:
  • ModelAttribute的使用:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档