Spring验证请求主体为字符串

问题描述 投票:0回答:1

我有这样的端点:

@PostMapping("/phone-number")
public ConfirmableResponse<String> createPhoneNumberVerificationRequest(@RequestBody @NotBlank @Size(min = 1, max = 20) String phoneNumber) {

...

但是正如我所见,注释@Size不起作用。为什么?怎样用@ Pattern注释验证phoneNumber

java spring validation spring-mvc endpoint
1个回答
0
投票
您需要使用@Valid批注进行验证。
© www.soinside.com 2019 - 2024. All rights reserved.