重写
    toString,
    https://jueee.github.io/2020/07/2020-07-15-%E5%85%B3%E4%BA%8EtoString%E6%96%B9%E6%B3%95%E7%9A%84%E9%87%8D%E5%86%99%E5%B7%A5%E5%85%B7ToStringBuilder/
    hashCode
    equeal
    clone

    引入依赖

    commons-lang
    commons-lang
    2.4

    1. import org.apache.commons.lang3.builder.EqualsBuilder;
    2. import org.apache.commons.lang3.builder.HashCodeBuilder;
    3. import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
    4. import org.apache.commons.lang3.builder.ToStringStyle;
    5. import java.io.Serializable;
    6. public class BaseEntity implements Serializable, Cloneable {
    7. /**
    8. * @see Object#toString()
    9. */
    10. @Override
    11. public String toString() {
    12. return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    13. }
    14. /**
    15. * @see Object#hashCode()
    16. */
    17. @Override
    18. public int hashCode() {
    19. return HashCodeBuilder.reflectionHashCode(this);
    20. }
    21. /**
    22. * @see Object#equals(Object)
    23. */
    24. @Override
    25. public boolean equals(Object obj) {
    26. return EqualsBuilder.reflectionEquals(this, obj);
    27. }
    28. /**
    29. * @see Object#clone()
    30. */
    31. @Override
    32. public Object clone() throws CloneNotSupportedException {
    33. return super.clone();
    34. }
    35. }