@RequestMapping(value="apiInventory/apis",method=RequestMethod.GET)
public Map<String,Object> getData(@NotNull @Valid @RequestParam("host") String host,
@NotNull @Valid @RequestParam("apiGroup") String basePath,
@RequestParam(value="path",required=false) String path,
@RequestParam(value="version",required=false) String version,
@Valid @Pattern(regexp="get|post|put|delete|patch|options") @RequestParam(value="httpMethod",required=false) String httpMethod,
@RequestParam(value="includeAttributeDefinition",required=false, defaultValue="false") boolean includeAttributeDefinition) throws Exception{
//My logic
}
我必须确保httpMethod
仅接受get、post、put、delete、patch、options的值
但是,验证并未进行。我本来期待一个错误,但当我发送无效的 httpMethod
时,没有抛出任何错误。我做错了什么?
最佳答案
您需要使用“@Validated”注释您的 Controller 类才能进行验证。
关于java - Spring Boot Controller 中未发生正则表达式验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54472986/