Search code examples
jspspring-mvcrequest-mapping

Return "viewName" + variable in Spring MVC


I have a methd in a @Controller, that return the name of the View:

@RequestMapping("/viewNameFiest")
public String methodName(){
       return "viewNameSecond";
}

How can I add a variable to the "return" line? A variable like this return "viewNameSecond/1";

In order to retrieve it with @RequestMapping("/viewNameSecond/{variable}")

Thank you


Solution

  • You can redirect:

    return "redirect:" + <URL in String>
    

    In your case:

    return "redirect:" + "/viewNameSecond/variable"; //create this URL String before return