验证路径变量大小

时间:2019-04-03 09:00:08

标签: java spring spring-boot validation spring-validator

我发现此示例如何验证路径变量:https://www.mkyong.com/spring-boot/spring-rest-validation-example/

@PostMapping(value = "/payment/{unique_transaction_id}")
      public ResponseEntity<StringResponseDTO> handleWpfMessage(@PathVariable("unique_transaction_id") @Valid @Max(32) String unique_transaction_id) throws Exception {

我可以添加@Valid的字符串@Max(32)限制的婴儿,还是必须按照课程中的说明在班级添加@Validated

1 个答案:

答案 0 :(得分:2)

您可以为路径变量定义正则表达式

@PostMapping(value = "/payment/{unique_transaction_id:[a-zA-Z0-9]{0,32}}")