Can @PathVariable return null if it's not found?

前端 未结 6 1631
失恋的感觉
失恋的感觉 2020-12-13 14:17

Is it possible to make the @PathVariable to return null if the path variable is not in the url? Otherwise I need to make two handlers. One for /simple

6条回答
  •  天涯浪人
    2020-12-13 14:24

    @RequestMapping(value = {"/simple", "/simple/{game}"}, method = RequestMethod.GET)
    public ModelAndView gameHandler(@PathVariable(value="example",required = false) final String example)
    

    Try this approach, it worked for me.

提交回复
热议问题