开发者

hibernate validiate list of integer

I have a list of integer like this:

private List<Integer> indexes;

Is there a way to valid individual mem开发者_如何学Cber to be in a range of 0-9? I see @Range and @Valid but can't find a way to make it work with List.

Thanks for your help,


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜