Spring MVC 控制器:重定向而不将参数添加到我的 url [英] Spring MVC Controller: Redirect without parameters being added to my url

查看:32
本文介绍了Spring MVC 控制器:重定向而不将参数添加到我的 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在没有将参数添加到我的 URL 的情况下进行重定向.

I'm trying to redirect without parameters being added to my URL.

@Controller
...
public class SomeController
{
  ...
  @RequestMapping("save/")
  public String doSave(...)
  {
    ...
    return "redirect:/success/";
  }

  @RequestMapping("success/")
  public String doSuccess(...)
  {
    ...
    return "success";
  }

重定向后,我的 url 看起来总是像这样:.../success/?param1=xxx&param2=xxx.因为我希望我的 URL 是一种 RESTful 并且我在重定向后永远不需要参数,所以我不希望它们被添加到重定向中.

After a redirect my url looks always something like this: .../success/?param1=xxx&param2=xxx. Since I want my URLs to be kind of RESTful and I never need the params after a redirect, I don't want them to be added on a redirect.

有什么办法可以摆脱它们吗?

Any ideas how to get rid of them?

推荐答案

在 Spring 3.1 中使用选项 ignoreDefaultModelOnRedirect 禁用自动将模型属性添加到重定向:

In Spring 3.1 use option ignoreDefaultModelOnRedirect to disable automatically adding model attributes to a redirect:

<mvc:annotation-driven ignoreDefaultModelOnRedirect="true" />

这篇关于Spring MVC 控制器:重定向而不将参数添加到我的 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆