@RestController
public class RequestController {
@GetMapping("/param")
public String testParam(Map<String,Object> map,
Model model,
HttpServletRequest request,
HttpServletResponse response){
map.put("hello","tengfei");
model.addAttribute("helloa","liu");
request.setAttribute("message","xiaofei");
Cookie cookie=new Cookie("woShi","tengFei");
response.addCookie(cookie);//response响应时添加一个cookie
return "forward:/success";
}
@ResponseBody
@GetMapping("/success")
public Map success(HttpServletRequest request){
Map<String,Object> map=new HashMap<>();
Object hello=request.getAttribute("hello");
Object helloa=request.getAttribute("helloa");
Object message=request.getAttribute("message");
map.put("hello",hello);
map.put("helloa",helloa);
map.put("message",message);
return map;
}
}
==只需要把@RestController换成@Controller即可 ==