标签:Map import ModelMap springframework Date modelAndView date org Model
我们用不同的方式来实现数据的 传递:
package com.lagou.edu.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.Date;
import java.util.Map;
/**
* @author lyj
* @Title: DemoController
* @ProjectName springmvc-demo
* @Description: TODO
* @date 2020/6/9 21:21
*/
@Controller
@RequestMapping("/demo")
public class DemoController {
/**
* http://localhost:8080/demo/handle01
*/
@RequestMapping("/handle01")
public ModelAndView handle01(){
Date date=new Date();
ModelAndView modelAndView=new ModelAndView();
modelAndView.addObject("date",date);
modelAndView.setViewName("success");
System.out.println("modelAndView----"+modelAndView.getClass());
return modelAndView;
}
/**
* http://localhost:8080/demo/handle02
*/
@RequestMapping("/handle02")
public String handle02(ModelMap modelMap){
Date date=new Date();
modelMap.addAttribute("date",date);
System.out.println("modelMap------"+modelMap.getClass());
return "success";
}
/**
* http://localhost:8080/demo/handle03
*/
@RequestMapping("/handle03")
public String handle03(Model model){
Date date=new Date();
model.addAttribute("date",date);
System.out.println("model-----"+model.getClass());
return "success";
}
/**
* http://localhost:8080/demo/handle04
*/
@RequestMapping("/handle04")
public String handle04(Map<String,Object>map){
Date date=new Date();
map.put("date",date);
System.out.println("map------"+map.getClass());
return "success";
}
}
下面我们来看输出结果:
modelAndView----class org.springframework.web.servlet.ModelAndView
modelMap------class org.springframework.validation.support.BindingAwareModelMap
model-----class org.springframework.validation.support.BindingAwareModelMap
map------class org.springframework.validation.support.BindingAwareModelMap
说明他们最后都是执行的BindingAwareModelMap
ModelMap:
LinkedHashMap是jdk里面的 package java.util;
Model:
Map:
Map也是java.util下面的
BindingAwareModelMap
标签:Map,import,ModelMap,springframework,Date,modelAndView,date,org,Model 来源: https://www.cnblogs.com/liuyj-top/p/13137761.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。