我发现这个示例如何验证路径变量: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 {
我可以添加 String @Max(32)
限制的 @Valid
婴儿吗?或者我必须在类级别添加 @Validated
正如教程中所示?
最佳答案
您可以为路径变量定义正则表达式
@PostMapping(value = "/payment/{unique_transaction_id:[a-zA-Z0-9]{0,32}}")
关于java - 验证路径变量大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55491110/