guyeuro
V2EX  ›  问与答

SpringMVC 里的多个 pathvariable 的问题

  •  
  •   guyeuro · Sep 11, 2017 · 3044 views
    This topic created in 3260 days ago, the information mentioned may be changed or developed.

    譬如

           @RequestMapping(value = "/getValue/{colorId}/{locationId}", method = RequestMethod.GET)
    

    我希望可以有两种请求

    1 /getValue/red/beijing

    2 /getValue/red

    而且当请求为 /getValue/red 的时候,类似于下面的判断生效

            if(locationId == null){
               dosomthing;
            }
    

    有这种操作吗?

    1 replies    2017-09-11 21:05:28 +08:00
    kevinzhwl
        1
    kevinzhwl  
       Sep 11, 2017 via iPhone
    简单的方法,写两个映射即可
    复杂的方法,locateid 用正则。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   870 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 20:56 · PVG 04:56 · LAX 13:56 · JFK 16:56
    ♥ Do have faith in what you're doing.