java Spring 3.0 MVC:重定向而不将参数添加到我的 url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17676206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 14:38:49  来源:igfitidea点击:

Spring 3.0 MVC :Redirect without parameters being added to my url

javaspring-mvc

提问by Federico

I'm trying to redirect without parameters being added to my url. I mean after a redirect, my url looks like this: .../success/?param1=xxx&param2=xxx.

我正在尝试在没有将参数添加到我的 url 的情况下进行重定向。我的意思是重定向后,我的网址如下所示:.../success/?param1=xxx¶m2=xxx。

This issue is exactly the same as this Spring MVC Controller: Redirect without parameters being added to my url

这个问题和这个Spring MVC 控制器完全一样:Redirect without parameters are added to my url

The response https://stackoverflow.com/a/16841663/384984is what I'm looking (ignoreDefaultModelOnRedirect). The problem is that I'm using Spring 3.0. How can I solve it with this Spring version?

响应https://stackoverflow.com/a/16841663/384984就是我正在寻找的(ignoreDefaultModelOnRedirect)。问题是我使用的是 Spring 3.0。我如何用这个 Spring 版本解决它?

回答by NINCOMPOOP

  1. You can simply clear the Modelmap in your Controllermethod before redirect .

    model.asMap().clear();
    return "redirect:" + yourURL;
    
  2. Don't expose the model attributes at all.

    RedirectView view = new RedirectView(yourURL, true);
    view.setExposeModelAttributes(false);
    return new ModelAndView(view); 
    
  3. Hope this linkhelps you in finding a better solution, specially point (4) HandlerInterceptorfor common reference data within the entire web application

  1. 您可以在重定向之前简单地清除方法中的Model地图Controller

    model.asMap().clear();
    return "redirect:" + yourURL;
    
  2. 根本不要公开模型属性。

    RedirectView view = new RedirectView(yourURL, true);
    view.setExposeModelAttributes(false);
    return new ModelAndView(view); 
    
  3. 希望此链接可以帮助您找到更好的解决方案,特别HandlerInterceptor是整个 Web 应用程序中常见参考数据的第(4) 点