在我的应用程序中,我有一个端点,它获取此对象的 JSON,然后调用calculateSomething()
以将数字作为 http 响应返回。我用 . 验证这些值javax.validation
。现在我有没有一种可能的方法来指定如何Example
验证类的对象,或者在这个特定的端点(我有多个端点)中验证该对象的哪些值?例如,在这种情况下,如果此端点被调用,则只有和one
将被验证,因为这些是 所需的唯一值。two
three
calculateSomething()
班级:
@Entity
@PrimaryKeyJoinColumn(name = "five")
public class Example extends Foo {
@ValidOne
@Column
private Integer one;
@ValidTwo
@Column
private Integer two;
@ValidThree
@Column
private Integer three;
@ValidFour
@Column
private Integer four;
@ValidFive
@Column
private Integer five;
@Override
public Integer calculateSomething() throws IllegalArgumentException{
(one + two) * three
}
}
端点:
@PostMapping ("/calculateSomeNumber")
public ResponseEntity calculateSomeNumber(@Valid @RequestBody Example example){
return ResponseEntity.ok(example.calculateSomething());
}