Spring Boot REST @RequestParam not being Validated

前端 未结 3 651
慢半拍i
慢半拍i 2020-12-13 09:58

I have tried a number of examples from the net and cannot get Spring to validate my query string parameter. It doesn\'t seem execute the REGEX / fail.

packag         


        
3条回答
  •  情话喂你
    2020-12-13 10:46

    You have incorrect regex

    "^[0-9]+(,[0-9]+)*$"
    

    It will never parse

    1,bob
    

    Maybe, you need:

    "^\w+(,\w+)*$"
    

    And if you need to parse also an empty line, use:

    "^(\w+(,\w+)*)?$"
    

提交回复
热议问题