java - Spring Boot Controller 中未发生正则表达式验证

标签 java regex spring spring-boot

@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/

相关文章:

如果条件删除列名称中的字符串

r - 将字符串数据转换为数据框

javascript - 在字符串中搜索多个单词

spring - Azure B2C 访问 token NULL Spring OAuth 2.0

java - Spring LdapTemplate 使用单独的过滤器在多个基础上进行搜索

java - 如何打印增强型 for 循环的前 10 行

java - 如何从垃圾邮件 System.out 中阻止 apache.commons.logging?

java - 如何以编程方式调用自定义导航器中节点上的 `Refresh` 功能?

java - 切割字符串java

java - Spring:获取具有特定参数的原型(prototype) bean 实例