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

前端 未结 6 1600
失恋的感觉
失恋的感觉 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:45

    You could always just do this:

    @RequestMapping(value = "/simple", method = RequestMethod.GET)
    public ModelAndView gameHandler(HttpServletRequest request) {
        gameHandler2(null, request)
    }
    
    @RequestMapping(value = "/simple/{game}", method = RequestMethod.GET)
    public ModelAndView gameHandler2(@PathVariable("game") String game,
            HttpServletRequest request) {
    

提交回复
热议问题