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

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

问题描述

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

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

  • Model
  • ModelMap
  • ModelAndView
  • Model
  • 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天全站免登陆