We are using spring-boot
.
I want to add conditional based constraint in java class.
For e.g.
@Entity
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "user_id")
private Integer userId;
@Column(name = "firstName")
private String firstName;
@Column(name = "lastName")
private String lastName;
}
Now in above code I want to put @NotNull
constraint on lastName
property if and only if the firstName
property is not empty.