Optional path variables in Spring-MVC RequestMapping URITemplate

后端 未结 4 1255
暖寄归人
暖寄归人 2021-02-20 12:10

I have the following mapping:

@RequestMapping(value = \"/{first}/**/{last}\", method = RequestMethod.GET)
public String test(@PathVariable(\"first\") String firs         


        
4条回答
  •  醉话见心
    2021-02-20 12:40

    It could be done by writing a custom path matcher and configuring Spring to use it. For example, such a solution is documented here: http://java.dzone.com/articles/spring-3-webmvc-optional-path

    The link provides a custom path matcher and shows how to configure spring to use it. That should solve your need if you don't mind writing a custom component.

    Also, this is a duplicate of With Spring 3.0, can I make an optional path variable?

提交回复
热议问题