1

I have a @Controller with the following @RequestMapping annotation

@RequestMapping(value={"somevalue"}, 
                method=RequestMethod.GET,
                produces=MediaType.TEXT_HTML_VALUE)
public String findOneById(@PathVariable String id, Model model){
    model.addAttribute(findOneById(id));
    return "some view";
}

Observe it uses @PathVariable, based on URI, it works around /persons/{id}, for example for:

  • /persons/100
  • /persons/200

it retrieves an expected person.

that @RequestMapping method works fine when:

  • I put the URL/URI in the same Web Browser address bar (.../persons/200)
  • when I generate a report of items including for each one a link to see the details (.../persons/200).

I am trying to create a search form such as follows:

<body>

        <spring:url var="findOne" value="/persons/" >

        </spring:url>

        <form action="${findOne}" method="get">     
            <table>
                <tr>
                    <td><label for="id"><spring:message code="persona.id.label"/></label></td>
                    <td><input name="id" id="id" value=""/></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" value="search"/></td>
                </tr>
            </table>
        </form>
    </body>

My problem is, when I press submit the form always generates/creates the URL to do the search in the format /persons?id=100. I know it is normal and is expected.

But just being curious and of course if is possible:

Question:

What would be the new configuration to generate a URI pattern such as /persons/100 instead of /persons?id=100 when I press the submit button?

I want avoid create a new @RequestMapping method working around with a @RequestParam (it for ?id=100). It to complement the @RequesMapping method working with @PathVariable (it for /100) version.

Thanks

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158

0 Answers0