当我们需要把某个值从一个请求redirect到另一个请求,那可能就取不到值,这个时候就可以用@SesstionAttributes这个注解了
@SesstionAttributes是作用在类上的
@Controller
@SessionAttributes(value = {"path"}) //这定义需要临时放在session里的参数名称
public class UserController extends BaseController {
/**do something*/
}
当我们去执行这样一个请求,需要重定向(redirect)到另一个请求,而在另一个请求里需要取到这个请求里边的参数,怎么办呢, 注意, 我里边有个path参数
@RequestMapping("redirectTest")
public String redirectTest(Model model){
model.addAttribute("path","mypath");
return "redirect:indexView";
}
@RequestMapping("indexView")
public ModelAndView indexView(ModelMap modelMap, SessionStatus sessionStatus){
ModelAndView view = new ModelAndView();
view.setViewName("index");
System.out.println(modelMap.get("path"));
sessionStatus.setComplete(); //这一样必须要有
return view;
}