Код: Выделить всё
@Entity
@Table(name = "article")
@Data
@NoArgsConstructor
public class Article {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name", nullable = false)
@NotNull(message="Article name cannot be null.")
@NotEmpty(message="Article name cannot be empty.")
private String name;
@Column(name = "articlenumber", nullable = false)
@NotNull(message="Article number cannot be null.")
@NotEmpty(message="Article number cannot be empty.")
private String articlenumber;
}
< /code>
В моей статье я использую @valid в таком методе, как это: < /p>
@Transactional
public Article createArticle(@Valid Article article) {
if (articleRepository.findByArticleNumber(article.getArticlenumber()) != null) {
throw new IllegalArgumentException("Article with this articlenumber already exists.");
}
articleRepository.persist(article);
return article;
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... validation
Мобильная версия