guyeuro
V2EX  ›  问与答

SpringMVC 里的多个 pathvariable 的问题

  •  
  •   guyeuro · Sep 11, 2017 · 2945 views
    This topic created in 3200 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   ·   1110 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 23:07 · PVG 07:07 · LAX 16:07 · JFK 19:07
    ♥ Do have faith in what you're doing.