如何基于Spring中的参数重定向到新的URL

时间:2017-02-19 11:32:38

标签: spring url-redirection

我的RequestMapping& ResponseBody是这样的:

@RequestMapping(value = "/someURL", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ModelAndView getDetails(
        @RequestParam(value = "param1", required = false) String param1,
        @RequestParam(value = "param2", required = false) String param2,
 {

现在基于param1,我想重定向到特定的URL。 例如。现在处理后,我的页面将进入

http://parent-domain/someURL?param1=...param2=... 

但我想要的是像这样完全改变父域

http://some-other-domain/someURL?param1=...param2=... 

1 个答案:

答案 0 :(得分:1)

做这样的事情:

    @RequestMapping(value = "/someURL", method = RequestMethod.GET, produces = "application/json")
    public ModelAndView getDetails(@RequestParam(value = "param1", required = false) String param1,
                                   @RequestParam(value = "param2", required = false) String param2) {
        if (param1.equals("a"))
            return new ModelAndView("redirect:somotherurl"); 
        else
            return new ModelAndView("redirect:http://google.com");
    }

如果param1是a,那么它会转到其他地方的某个地方,它会重定向到google.com