SpringMVC重定向(redirect)传参数,前端EL表达式接受值

  由于重定向相当于2次请求,所以无法把参数加在model中传过去。在上面例子中,页面获取不到msg参数。要想获取参数,可以手动拼url,把参数带在后面。Spring 3.1 提供了一个很好用的类:RedirectAttributes。 使用这个类,我们可以把参数随着重定向传到页面,不需自己拼url了。

  addFlashAttribute()。这个方法原理是放到session中,session在跳到页面后马上移除对象,所以你刷新一下后这个值就会丢失。

在SpringMvc的Controller中使用:

@RequestMapping("/ss")
public String gg(RedirectAttributes model){
  model.addFlashAttribute(
"msg","未登录!!!");   return "redirect:/show"; }

前端:

${msg}








猜你喜欢

转载自www.cnblogs.com/crazy-lc/p/12299792.html
今日推荐