6

我有一个这样的整数列表:

private List<Integer> indexes;

有没有办法让个人成员有效在 0-9 的范围内?我看到了@Range 和@Valid,但找不到让它与List 一起工作的方法。

谢谢你的帮助,

4

1 回答 1

1

Only @Size and @Valid can be used on Collections, however you can use some wrapper object instead of "Integer" to validate your ints, e.g.:

public class Index {
  @Range( min = 0, max = 9 )
  private Integer value;
}

public class Container {
  @Valid
  private List<Index> indexes;
}

This should do the trick

于 2014-02-18T10:30:00.657 回答