企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] # 下载Hibernate5 https://sourceforge.net/projects/hibernate/files/hibernate-orm/5.0.7.Final/ 解压完后,目录结构如下 ![](https://box.kancloud.cn/6f287f4b281b90eab11799208d2a8be4_504x392.png) ![](https://box.kancloud.cn/6642082f3d4b5c3fcb124f74c539b12f_1664x404.png) 包含的都是必要的jar包 # 引入Hibernate包 ![](https://box.kancloud.cn/6e74f9da1e4d65c1196fcbfe0c300a50_708x1076.png) # 准备表 ~~~ CREATE table `cst_customer` ( `cust_id` bigint(32) not null auto_increment comment '客户编号(主键)', `cust_name` varchar(32) not null comment '客户名称(公司名称)', `cust_source` varchar(32) default null comment '客户信息来源', `cust_industry` varchar(32) default null comment '客户所属行业', `cust_level` varchar(32) default null comment '客户级别', `cust_phone` varchar(64) default null comment '固定电话', `cust_mobile` varchar(16) default null comment '移动电话', primary key(`cust_id`) ) engine=Innodb AUTO_INCREMENT=1 default charset=utf8; ~~~ 在项目src下,创建domain包,并在包下创建实体类Customer(对应数据库cst_customer),Customer类包含与cst_customer数据表字段对应的属性,已经setXX,getXX方法 ~~~ package domain; public class Customer { private Long cust_id; private String cust_name; private String cust_source; private String cust_industry; private String cust_level; private String cust_phone; private String cust_mobile; public Long getCust_id() { return cust_id; } public void setCust_id(Long cust_id) { this.cust_id = cust_id; } public String getCust_name() { return cust_name; } public void setCust_name(String cust_name) { this.cust_name = cust_name; } public String getCust_source() { return cust_source; } public void setCust_source(String cust_source) { this.cust_source = cust_source; } public String getCust_industry() { return cust_industry; } public void setCust_industry(String cust_industry) { this.cust_industry = cust_industry; } public String getCust_level() { return cust_level; } public void setCust_level(String cust_level) { this.cust_level = cust_level; } public String getCust_phone() { return cust_phone; } public void setCust_phone(String cust_phone) { this.cust_phone = cust_phone; } public String getCust_mobile() { return cust_mobile; } public void setCust_mobile(String cust_mobile) { this.cust_mobile = cust_mobile; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((cust_id == null) ? 0 : cust_id.hashCode()); result = prime * result + ((cust_industry == null) ? 0 : cust_industry.hashCode()); result = prime * result + ((cust_level == null) ? 0 : cust_level.hashCode()); result = prime * result + ((cust_mobile == null) ? 0 : cust_mobile.hashCode()); result = prime * result + ((cust_name == null) ? 0 : cust_name.hashCode()); result = prime * result + ((cust_phone == null) ? 0 : cust_phone.hashCode()); result = prime * result + ((cust_source == null) ? 0 : cust_source.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Customer other = (Customer) obj; if (cust_id == null) { if (other.cust_id != null) return false; } else if (!cust_id.equals(other.cust_id)) return false; if (cust_industry == null) { if (other.cust_industry != null) return false; } else if (!cust_industry.equals(other.cust_industry)) return false; if (cust_level == null) { if (other.cust_level != null) return false; } else if (!cust_level.equals(other.cust_level)) return false; if (cust_mobile == null) { if (other.cust_mobile != null) return false; } else if (!cust_mobile.equals(other.cust_mobile)) return false; if (cust_name == null) { if (other.cust_name != null) return false; } else if (!cust_name.equals(other.cust_name)) return false; if (cust_phone == null) { if (other.cust_phone != null) return false; } else if (!cust_phone.equals(other.cust_phone)) return false; if (cust_source == null) { if (other.cust_source != null) return false; } else if (!cust_source.equals(other.cust_source)) return false; return true; } @Override public String toString() { return "Customer [cust_id=" + cust_id + ", cust_name=" + cust_name + ", cust_source=" + cust_source + ", cust_industry=" + cust_industry + ", cust_level=" + cust_level + ", cust_phone=" + cust_phone + ", cust_mobile=" + cust_mobile + "]"; } } ~~~