一, 创建表: worker_node(在项目启动时初始化生成workId)
CREATE TABLE `worker_node` (
`ID` bigint NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
`HOST_NAME` varchar(64) NOT NULL COMMENT 'host name',
`PORT` varchar(64) NOT NULL COMMENT 'port',
`TYPE` int NOT NULL COMMENT 'node type: ACTUAL or CONTAINER',
`LAUNCH_DATE` date NOT NULL COMMENT 'launch date',
`MODIFIED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'modified time',
`CREATED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'created time',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb3 COMMENT='DB WorkerID Assigner for UID Generator';
二, 创建Model及Exmple、Dao
Model: WorkerNode
package org.com.spi.model;
import java.util.Date;
public class WorkerNode {
private Long id;
private String hostName;
private String port;
private Integer type;
private Date launchDate;
private Date modified;
private Date created;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName == null ? null : hostName.trim();
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port == null ? null : port.trim();
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public Date getLaunchDate() {
return launchDate;
}
public void setLaunchDate(Date launchDate) {
this.launchDate = launchDate;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
}
Example: WorkerNodeExample
package org.com.spi.model;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public class WorkerNodeExample {
protected String orderByClause;
protected boolean distinct;
protected List oredCriteria;
public WorkerNodeExample() {
oredCriteria = new ArrayList();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List getAllCriteria() {
return criteria;
}
public List getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
protected void addCriterionForJDBCDate(String condition, Date value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
addCriterion(condition, new java.sql.Date(value.getTime()), property);
}
protected void addCriterionForJDBCDate(String condition, List values, String property) {
if (values == null || values.size() == 0) {
throw new RuntimeException("Value list for " + property + " cannot be null or empty");
}
List dateList = new ArrayList();
Iterator iter = values.iterator();
while (iter.hasNext()) {
dateList.add(new java.sql.Date(iter.next().getTime()));
}
addCriterion(condition, dateList, property);
}
protected void addCriterionForJDBCDate(String condition, Date value1, Date value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
addCriterion(condition, new java.sql.Date(value1.getTime()), new java.sql.Date(value2.getTime()), property);
}
public Criteria andIdIsNull() {
addCriterion("ID is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("ID is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(Long value) {
addCriterion("ID =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(Long value) {
addCriterion("ID <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(Long value) {
addCriterion("ID >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(Long value) {
addCriterion("ID >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(Long value) {
addCriterion("ID <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(Long value) {
addCriterion("ID <=", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List values) {
addCriterion("ID in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List values) {
addCriterion("ID not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(Long value1, Long value2) {
addCriterion("ID between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(Long value1, Long value2) {
addCriterion("ID not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andHostNameIsNull() {
addCriterion("HOST_NAME is null");
return (Criteria) this;
}
public Criteria andHostNameIsNotNull() {
addCriterion("HOST_NAME is not null");
return (Criteria) this;
}
public Criteria andHostNameEqualTo(String value) {
addCriterion("HOST_NAME =", value, "hostName");
return (Criteria) this;
}
public Criteria andHostNameNotEqualTo(String value) {
addCriterion("HOST_NAME <>", value, "hostName");
return (Criteria) this;
}
public Criteria andHostNameGreaterThan(String value) {
addCriterion("HOST_NAME >", value, "hostName");
return (Criteria) this;
}
public Criteria andHostNameGreaterThanOrEqualTo(String value) {
addCriterion("HOST_NAME >=", value, "hostName");
return (Criteria) this;
}
public Criteria andHostNameLessThan(String value) {
addCriterion("HOST_NAME <", value, "hostName");
return (Criteria) this;
}
public Criteria andHostNameLessThanOrEqualTo(String value) {
addCriterion("HOST_NAME <=", value, "hostName");
return (Criteria) this;
}
public Criteria andHostNameLike(String value) {
addCriterion("HOST_NAME like", value, "hostName");
return (Criteria) this;
}
public Criteria andHostNameNotLike(String value) {
addCriterion("HOST_NAME not like", value, "hostName");
return (Criteria) this;
}
public Criteria andHostNameIn(List values) {
addCriterion("HOST_NAME in", values, "hostName");
return (Criteria) this;
}
public Criteria andHostNameNotIn(List values) {
addCriterion("HOST_NAME not in", values, "hostName");
return (Criteria) this;
}
public Criteria andHostNameBetween(String value1, String