本文介绍了如何将@EqualsAndHashCode与Include一起使用-Lombok的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 @EqualsAndHashCode
与 Include
一起使用Lombok Java库。
How to use @EqualsAndHashCode
With Include
, Lombok library for Java.
@EqualsAndHashCode.Include( )
如何使Equals比较班级ID?
How to make Equals compare the class id?
示例:
@EqualsAndHashCode.Include( )
@Table(name = "USER")
public class User
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "IDENTITY_USER")
private Long identity;
}
推荐答案
Include
注释用于要包含在 equals
和 hashCode $ c中的成员上$ c>方法。如果您想确切指定应使用的成员(而不是所有非静态非瞬态成员的默认值),则可以在选项卡中使用
onlyExplicitlyIncluded = true
选项 @EqualsAndHashCode
批注:
The Include
annotation is used on the member(s) you want to include in the equals
and hashCode
methods. If you want to specify exactly which members should be used (instead of the default of all non-static non-transient members), you could use the onlyExplicitlyIncluded = true
option in the @EqualsAndHashCode
annotation:
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Table(name = "USER")
public class User
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "IDENTITY_USER")
@EqualsAndHashCode.Include
private Long identity;
}
这篇关于如何将@EqualsAndHashCode与Include一起使用-Lombok的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!