search

Home  >  Q&A  >  body text

java - Is there any verification annotation to detect duplicate content in the list?

A certain interface requires the caller to pass a list. A certain string attribute in the object in the list cannot be repeated. Is there such an annotation to quickly determine whether there is duplicate data?
I searched for hibernate verification and found no such thing. How do you generally deal with this problem? If such judgment tests are required in many places, how to write public wheels. Thanks.

为情所困为情所困2833 days ago698

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-05-17 10:05:54

    You can just inherit it yourselfjavax.validation.ConstraintValidator实现一个jsr-303的注解不就行了, 简单的Set<String> set = new HashSet<>(list); list.size == set.size()

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-17 10:05:54

    Define an annotation to convert the list into a set. If the zise of the set is smaller than the list, it means there is duplication

    reply
    0
  • Cancelreply