**1、知识点:
- Map、Model**(给map、model里面添加的数据,会被放在request的请求域中。相当于request.setAttribute)。**
- Errors/BindingResult。
- RedirectAttributes**( 重定向携带数据)**。
- ServletResponse**(servlet中的response响应)**。
- SessionStatus。
- UriComponentsBuilder。
- ServletUriComponentsBuilder。
2、测试:**把Map、Model数据转发到另个处理器GetMapping中后,通过request域能否获取到对应的值.
package com.wzy.springbootweb01.controller;
@Controller
public class MyController9Request {
@GetMapping(value = "/params")
public String paramsTest(Map<String,Object> map,
Model model,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
//map集合中添加数据
map.put("key1","我是mapkey1的value.");
//model中添加数据
model.addAttribute("model","我是model中的数据.");
//request域中添加数据
request.setAttribute("request","我是request域中的数据");
//respones中添加cookie
Cookie cookie = new Cookie("CookieKey","CookieValue");
response.addCookie(cookie);
//request.getRequestDispatcher("success").forward(request,response);
return "forward:/success2";
}
@ResponseBody
@GetMapping(value = "/success2")
public Map paramsTest2( HttpServletRequest request) throws Exception{
HashMap<Object, Object> hashMap = new HashMap<>();
Object map = request.getAttribute("key1");//此处获取的是Map集合中Key1 的值,并非map集合.
Object model = request.getAttribute("model");
Object request1 = request.getAttribute("request");
Object cookie = request.getAttribute("cookie");
hashMap.put("map",map);
hashMap.put("model",model);
hashMap.put("request1",request1);
hashMap.put("cookie",cookie);
return hashMap;
}
}
Map、Model类型的参数,会返回 mavContainer.getModel();—-> BindingAwareModelMap 是Model 也是Map
mavContainer.getModel(); 获取到值的