1.1、如图将基本的架子搭建好
-
xml version=‘1.0’ encoding=‘utf-8’?>
-
-
“-//Hibernate/Hibernate Configuration DTD//EN”
-
“http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd”>
-
<hibernate-configuration>
-
<session-factory>
-
-
<property name=“connection.url”>jdbc:mysql://localhost:3306/SSHBlog?useUnicode=true&characterEncoding=utf8&useSSL=true&zeroDateTimeBehavior=convertToNull
property>
-
-
<property name=“connection.driver_class”>com.mysql.jdbc.Driver
property>
-
-
<property name=“connection.username”>root
property>
-
-
<property name=“connection.password”>
property>
-
-
-
update –>
-
session-factory>
-
hibernate-configuration>
-
package com.sshblog.entity;
-
-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-
import javax.persistence.*;
-
import java.util.Date;
-
-
@Entity
-
@Table(name =
“contacts”)
-
@JsonIgnoreProperties(value = {
“hibernateLazyInitializer”,
“handler”,
“operations”,
“roles”,
“menus”})
-
public
class Contacts {
-
private
int id;
-
private String name;
-
private String address;
-
private String gender;
-
private Date dob;
-
private String email;
-
private Long mobile;
-
-
@Id
-
@Column(name =
“id”)
-
public int getId() {
-
return id;
-
}
-
-
public void setId(int id) {
-
this.id = id;
-
}
-
-
@Basic
-
@Column(name =
“name”)
-
public String getName() {
-
return name;
-
}
-
-
public void setName(String name) {
-
this.name = name;
-
}
-
-
@Basic
-
@Column(name =
“address”)
-
public String getAddress() {
-
return address;
-
}
-
-
public void setAddress(String address) {
-
this.address = address;
-
}
-
-
@Basic
-
@Column(name =
“gender”)
-
public String getGender() {
-
return gender;
-
}
-
-
public void setGender(String gender) {
-
this.gender = gender;
-
}
-
-
@Basic
-
@Column(name =
“dob”)
-
public Date getDob() {
-
return dob;
-
}
-
-
public void setDob(Date dob) {
-
this.dob = dob;
-
}
-
-
@Basic
-
@Column(name =
“email”)
-
public String getEmail() {
-
return email;
-
}
-
-
public void setEmail(String email) {
-
this.email = email;
-
}
-
-
@Basic
-
@Column(name =
“mobile”)
-
public Long getMobile() {
-
return mobile;
-
}
-
-
public void setMobile(Long mobile) {
-
this.mobile = mobile;
-
}
-
-
@Override
-
public boolean equals(Object o) {
-
if (
this == o)
return
true;
-
if (o ==
null || getClass() != o.getClass())
return
false;
-
-
Contacts contacts = (Contacts) o;
-
-
if (id != contacts.id)
return
false;
-
if (name !=
null ? !name.equals(contacts.name) : contacts.name !=
null)
return
false;
-
if (address !=
null ? !address.equals(contacts.address) : contacts.address !=
null)
return
false;
-
if (gender !=
null ? !gender.equals(contacts.gender) : contacts.gender !=
null)
return
false;
-
if (dob !=
null ? !dob.equals(contacts.dob) : contacts.dob !=
null)
return
false;
-
if (email !=
null ? !email.equals(contacts.email) : contacts.email !=
null)
return
false;
-
if (mobile !=
null ? !mobile.equals(contacts.mobile) : contacts.mobile !=
null)
return
false;
-
-
return
true;
-
}
-
-
@Override
-
public int hashCode() {
-
int result = id;
-
result =
31 * result + (name !=
null ? name.hashCode() :
0);
-
result =
31 * result + (address !=
null ? address.hashCode() :
0);
-
result =
31 * result + (gender !=
null ? gender.hashCode() :
0);
-
result =
31 * result + (dob !=
null ? dob.hashCode() :
0);
-
result =
31 * result + (email !=
null ? email.hashCode() :
0);
-
result =
31 * result + (mobile !=
null ? mobile.hashCode() :
0);
-
return result;
-
}
-
}
-
xml version=‘1.0’ encoding=‘utf-8’?>
-
-
“-//Hibernate/Hibernate Mapping DTD 3.0//EN”
-
“http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd”>
-
<hibernate-mapping>
-
-
<class name=“com.sshblog.entity.Contacts” table=“contacts” schema=“SSHBlog”>
-
<id name=“id” column=“id”/>
-
<property name=“name” column=“name”/>
-
<property name=“address” column=“address”/>
-
<property name=“gender” column=“gender”/>
-
<property name=“dob” column=“dob”/>
-
<property name=“email” column=“email”/>
-
<property name=“mobile” column=“mobile”/>
-
class>
-
hibernate-mapping>