V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
guyeuro
V2EX  ›  问与答

SpringMVC 里的多个 pathvariable 的问题

  •  
  •   guyeuro · Sep 11, 2017 · 2851 views
    This topic created in 3150 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   ·   4261 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 00:56 · PVG 08:56 · LAX 17:56 · JFK 20:56
    ♥ Do have faith in what you're doing.