我发现此示例如何验证路径变量: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
?
答案 0 :(得分:2)
您可以为路径变量定义正则表达式
@PostMapping(value = "/payment/{unique_transaction_id:[a-zA-Z0-9]{0,32}}")