mirror of https://github.com/halo-dev/halo
Customize PostTag#equals and PostTag#hashCode
parent
0d814e88a2
commit
c5e675ce66
|
@ -1,16 +1,16 @@
|
||||||
package cc.ryanc.halo.model.entity;
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
import cc.ryanc.halo.utils.DateUtils;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.hibernate.annotations.SQLDelete;
|
import org.hibernate.annotations.SQLDelete;
|
||||||
import org.hibernate.annotations.Where;
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Post tag entity.
|
||||||
|
*
|
||||||
* @author : RYAN0UP
|
* @author : RYAN0UP
|
||||||
* @date : 2019-03-12
|
* @date : 2019-03-12
|
||||||
*/
|
*/
|
||||||
|
@ -20,7 +20,6 @@ import java.util.Date;
|
||||||
@SQLDelete(sql = "update post_tags set deleted = true where id = ?")
|
@SQLDelete(sql = "update post_tags set deleted = true where id = ?")
|
||||||
@Where(clause = "deleted = false")
|
@Where(clause = "deleted = false")
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class PostTag extends BaseEntity {
|
public class PostTag extends BaseEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -45,4 +44,19 @@ public class PostTag extends BaseEntity {
|
||||||
super.prePersist();
|
super.prePersist();
|
||||||
id = null;
|
id = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
PostTag postTag = (PostTag) o;
|
||||||
|
return Objects.equals(postId, postTag.postId) &&
|
||||||
|
Objects.equals(tagId, postTag.tagId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), postId, tagId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue