⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idgenerator.java

📁 使用WEBWORK,SPRING,HIBERNATE编写的简单的添加
💻 JAVA
字号:
/**
 *文件功能: 
 */
package com.common.hibernate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.Configurable;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.type.Type;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Properties;
import com.common.util.StringUtil;
/**
 * @作者 徐建协
 * @日期 2008-1-21
 */
public class IdGenerator {
	private Log log = LogFactory.getLog(DateGenerator.class);
	public static String preDateTime = "";
	public static String currentDateTime = "";
	public static int seq = 0;
	public static byte[] lock = new byte[0];
	
	public static String getId(){
		currentDateTime = StringUtil.getCurDate("yyyyMMddHHmmss");
		String res = "";
		synchronized (lock) {
			if (currentDateTime.equals(preDateTime)) {
				seq++;
				if (seq < 10) {
					res = currentDateTime + "000" + seq;
				} else if (seq >= 10 && seq < 100) {
					res = currentDateTime + "00" + seq;
				} else if (seq >= 100 && seq < 1000) {
					res = currentDateTime + "0" + seq;
				} else if (seq >= 1000 && seq < 10000) {
					res = currentDateTime + seq;
				}else{
					//throw new Exception("generante error");
				}
			} else {
				res = currentDateTime + "0001";
				seq = 1;
			}
			preDateTime=currentDateTime;
		}
		return res;
	}
	//public String get
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for(int i=0;i<40;i++){
			System.out.println(IdGenerator.getId());
			System.out.println(IdGenerator.getId());
		}

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -