Model、ModelMap 和 ModelAndView 有什么区别? [英] What are the differences between Model, ModelMap, and ModelAndView?

查看:32
本文介绍了Model、ModelMap 和 ModelAndView 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 Spring Framework 类之间的主要区别是什么?

What are the main differences between the following Spring Framework classes?

  • 模型
  • ModelMap
  • ModelAndView

使用Model.put(String,Object)我们可以访问.jsp文件中的值,但是ModelMap.addAttribute(String,Object)代码> 也做了同样的事情.我不明白这些课程之间的区别.

Using Model.put(String,Object) we can access the values in .jsp files, but ModelMap.addAttribute(String,Object) also did same thing. I do not understand the difference between these classes.

推荐答案

Model 是一个接口,而 ModelMap 是一个类.

Model is an interface while ModelMap is a class.

ModelAndView 只是一个 ModelMap 和一个视图对象的容器.它允许控制器将两者作为单个值返回.

ModelAndView is just a container for both a ModelMap and a view object. It allows a controller to return both as a single value.

这篇关于Model、ModelMap 和 ModelAndView 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆