Java Spring - how to handle missing required request parameters

前端 未结 3 909
再見小時候
再見小時候 2021-02-01 16:53

Consider the following mapping:

@RequestMapping(value = \"/superDuperPage\", method = RequestMethod.GET)
public String superDuperPage(@RequestParam(value = \"som         


        
3条回答
  •  野的像风
    2021-02-01 17:28

    You can do this with Spring 4.1 onwards and Java 8 by leveraging the Optional type. In your example that would mean your @RequestParam String will have now type of Optional.

    Take a look at this article for an example showcasing this feature.

提交回复
热议问题