【发布时间】:2016-07-02 20:52:18
【问题描述】:
我有以下类,它有带有 @NotEmpty 注释的 errorRequests。
public class ErrorsRequests implements Serializable {
private static final long serialVersionUID = -727308651190295062L;
private String applicationName;
@NotEmpty
@Valid
@JsonProperty("errors")
private List<ErrorsRequest> errorRequests;
我的控制器如下所示:
@Autowired
@Qualifier("errorStreamValidator")
private Validator errorStreamValidator;
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Void> errorReporting(@NotNull @PathVariable String applicationName,
@Valid @NotNull @RequestBody ErrorsRequests errorsRequests, BindingResult results) {
我的类路径中有所需的休眠验证器类。
当我输入以下 JSON 时:
{
"errorss": [
]
}
@NotEmpty 验证根本没有启动。 Hibernate 验证仅在 json 中包含错误元素时才有效,如下所示
{
"errors": [
]
}
我可以让第一个案例也有效吗?
【问题讨论】:
-
用@NotBlank 也试过了,但也不起作用
标签: spring-mvc jackson hibernate-validator spring-restcontroller