【发布时间】:2022-11-26 02:15:49
【问题描述】:
我的POM:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
我的控制器:
@RestController @验证
方法名(@Valid @RequestBody POJO_NAME)
我的POJO
@Pattern(regexp="^[a-zA-Z0-9]{30}",message="uniqueId length must be 30")
private String uniqueId;
@Pattern(regexp="^[a-zA-Z0-9]{50}",message="authId length must be 50")
private String authId;
每当我尝试点击发布请求(有和没有有效值)时,我都会在邮递员下面
{
"timestamp": "2022-11-24T16:51:26.733+00:00",
"status": 400,
"error": "Bad Request",
"path": "path/to/post/request"
}
请帮助我找出我的代码中缺少什么阻止验证按预期工作。
【问题讨论】:
-
您能否分享两种情况下的 curl 请求?
-
uniqueId 超过 30 个字符的错误卷曲:curl --location --request POST 'localhost:8080/servicecatalogue/ECOM/1234/inquiry' \ --header 'Content-Type: application/json' \ --data-raw '"authId": "userId", “authPassword”:“************”,“serviceId”:“1984120645”,“uniqueId”:“zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz”,“serviceAmount”:100,“数量”:2'
标签: java spring-boot validation pojo bad-request