当我在方法中使用返回重定向
时,Spring会自动添加我的模型变量,例如将参数获取到url。
我在这里找到了解决方案 Spring MVC Controller: Redirect without parameters being added to my url
但不幸的是它不适用于 spring 3.2
我还发现了以下
When upgrading to spring-mvc-4.0.xsd, you should replace enableMatrixVariables and ignoreDefaultModelOnRedirect with enable-matrix-variables and ignore-default-model-on-redirect respectively.
但是当我将其添加到我的 mvc-dispatcher.xml 时,我的 IDE 表示此处不允许使用该属性。
有Spring 3.2的解决方案吗?
最佳答案
如果您使用 java 配置,请将以下内容添加到您的 WebMvcConfigurerAdapter
子类中:
@Autowired
private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
@PostConstruct
public void init() {
requestMappingHandlerAdapter.setIgnoreDefaultModelOnRedirect(true);
}
关于java - Spring自动将模型参数添加到url中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26175340/