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

后端 未结 6 420
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 04:58

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

@Controller
...
public class SomeController
{
  ..         


        
6条回答
  •  [愿得一人]
    2020-11-30 05:03

    In Spring 4 there is a way to do this with java config, using annotations. I'm sharing it in case anyone needs it as I needed it.

    On the config class that extends WebMvcConfigurerAdapter, you need to add:

    @Autowired
    private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
    
    
    @PostConstruct
    public void init() {
        requestMappingHandlerAdapter.setIgnoreDefaultModelOnRedirect(true);
    }
    

    With this, you do not need to use RedirectAttributes, and it is an equivalent in java config to Matroskin's answer.

提交回复
热议问题