@RequestMapping(value = \"/Foo/{id}/{friendlyUrl:.*}\", method = RequestMethod.GET)
public ModelAndView getFoo(@PathVariable final Long id, @PathVariable final String
In your code you have
foo = fooService.get(id); //use id from pathvariable
redirectView = new RedirectView(foo.getCorrectUrl()); //set url to correct url, not that in path
redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY); //moved permanently
modelAndView = new ModelAndView(redirectView);
modelAndView.setViewName("myFoo.jsp");
return modelAndView;
The call to modelAndView.setViewName("myFoo.jsp");
effectively replaces the value of View (redirectView reference) that was passed to ModelAndView contructor.
So you should not call setViewName in this case.