私のアプリケーションには、このオブジェクトの 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());
}