关闭

Java toString equals hashCode 方法的重写

269人阅读 评论(0) 收藏 举报
分类:

package com.milk.entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 *
 * @author admin
 */
@Entity
public class City implements Serializable {
 private static final long serialVersionUID = 1L;
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 private Long id;

 public Long getId() {
  return id;
 }

 public void setId(Long id) {
  this.id = id;
 }

 @Override
 public int hashCode() {
  int hash = 0;
  hash += (id != null ? id.hashCode() : 0);
  return hash;
 }

 @Override
 public boolean equals(Object object) {
   if (!(object instanceof City)) {
   return false;
  }
  City other = (City) object;
  if ((this.id == null && other.id != null)
    || (this.id != null && !this.id.equals(other.id))) {
   return false;
  }
  return true;
 }

 @Override
 public String toString() {
  return "com.milk.entity.City.id=" + id + " ";
 }

}

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:29241次
    • 积分:544
    • 等级:
    • 排名:千里之外
    • 原创:20篇
    • 转载:41篇
    • 译文:2篇
    • 评论:0条