现在的位置: 首页 > 综合 > 正文

枚举的诸多使用方法enum–构造方法,普通方法method,获取枚举,实现接口

2013年04月04日 ⁄ 综合 ⁄ 共 958字 ⁄ 字号 评论关闭

/**
 * 表映射为对象类
 *
 */
public class TableObjects {

	public enum ColumnType {

		INTEGER,DOUBLE,CHAR,VARCHAR,FLOAT
	}
	
	interface table
	{
		ColumnType getType();
		int getColLength();
		String getColName();
		table getColumn(String colName);
		table[] getColumns();
	}
	
	public enum t_user implements table
	{
		//id的长度无论是否设置都是11(mysql数据库)
		id("id",11,ColumnType.INTEGER),
		username("username",30,ColumnType.VARCHAR),
		password("password",30, ColumnType.VARCHAR);
		
		 String colName = null;
		 int colLength = 0;
		 ColumnType type = null;
		 
		public String getColName() {
			return colName;
		}

		public int getColLength() {
			return colLength;
		}

		public ColumnType getType() {
			return type;
		}
		
		private t_user(String colName, int colLength, ColumnType type)
		{
			this.colName = colName;
			this.colLength = colLength;
			this.type = type;
		}

		/**
		 * 根据列名获取列结构
		 * @param colName
		 * @return
		 */
		public t_user getColumn(String colName) {
			for (t_user colEnum : t_user.values()) {
				if(colName.equals(colEnum.getColName()))
				{
					return colEnum;
				}
			}
			return null;
		}
		
		/**
		 * 获取所有列结构
		 * @return
		 */
		public t_user[] getColumns()
		{
			return t_user.values();
		}
	}
	
	/**
	 * 下面继续写别的映射类,有多少写多少
	 */
}

抱歉!评论已关闭.