V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
guyeuro
V2EX  ›  问与答

SpringMVC 里的多个 pathvariable 的问题

  •  
  •   guyeuro · 2017-09-11 17:24:06 +08:00 · 2232 次点击
    这是一个创建于 2420 天前的主题,其中的信息可能已经有所发展或是发生改变。

    譬如

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

    我希望可以有两种请求

    1 /getValue/red/beijing

    2 /getValue/red

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

            if(locationId == null){
               dosomthing;
            }
    

    有这种操作吗?

    1 条回复    2017-09-11 21:05:28 +08:00
    kevinzhwl
        1
    kevinzhwl  
       2017-09-11 21:05:28 +08:00 via iPhone
    简单的方法,写两个映射即可
    复杂的方法,locateid 用正则。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   881 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:34 · PVG 04:34 · LAX 13:34 · JFK 16:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.