如何验证 Spring Boot Rest 响应?
2022-09-04 21:36:17
我有使用Spring Boot Rest实现的控制器:
@RestController
@RequestMapping("/example")
public class ExampleController {
@Autowired
private ExampleService exampleService;
@GetMapping("/{id}")
public ExampleResponse getExample(@NotNull @PathVariable("id") String id) {
return exampleService.getExample(id);
}
}
和响应 DTO:
public class ExampleResponse {
@NotNull
private String id;
@NotNull
private String otherStuff;
// setters and getters
}
未验证响应正文。我已经用注释了它,但值仍然通过。请求验证效果很好。@Valid
null
如何验证响应正文?