/**
* 表映射为对象类
*
*/
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();
}
}
/**
* 下面继续写别的映射类,有多少写多少
*/
}