?? arecorderbeancreator.java
字號(hào):
package turing;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Hashtable;
import java.util.Vector;
class ARecorderBeanCreator
{
Hashtable ht_columnType;
Hashtable ht_default;
String tableName;
String packageName;
ARecorderBeanCreator(String tableName,String packageName)
{
this.tableName=tableName;
this.packageName=packageName;
ht_columnType=new Hashtable();
ht_columnType.put("char","String");
ht_columnType.put("varchar","String");
ht_columnType.put("datetime","String");
ht_columnType.put("int","int");
ht_columnType.put("bit","boolean");
ht_columnType.put("decimal","double");
ht_default=new Hashtable();
ht_default.put("char","null");
ht_default.put("varchar","null");
ht_default.put("datetime","null");
ht_default.put("int","0");
ht_default.put("bit","true");
ht_default.put("decimal","0.0");
}
String abc2Abc(String abc)
{
return abc.substring(0,1).toUpperCase()+abc.substring(1);
}
void createARecorderBean(Vector v_col) throws Exception
{
BufferedWriter out = new BufferedWriter(new FileWriter("com/"+tableName+".java"));
out.write("package "+packageName+";\n");
out.write("public class "+tableName+"\n{\n");
createColumnDeclare(v_col,out);
out.write("\n\t public "+tableName+"()\n\t {\n");
createDefaultValue(v_col,out);
out.write("\t }\n");
createSetGet(v_col,out);
out.write("}\n");
out.close();
}
void createDefaultValue(Vector v_col,BufferedWriter out) throws Exception
{
for(int i=0;i<v_col.size();i++)
{
Column col=(Column)v_col.get(i);
out.write("\t\t "+col.name +"="+ht_default.get(col.type)+";\n");
}
}
void createSetGet(Vector v_col,BufferedWriter out) throws Exception
{
for(int i=0;i<v_col.size();i++)
{
Column col=(Column)v_col.get(i);
out.write("\n");
out.write("\t public void set"+abc2Abc(col.name)+"("+ht_columnType.get(col.type)+" "+col.name+")\n");
out.write("\t {\n");
out.write("\t\t this."+col.name+"="+col.name+";\n");
out.write("\t }\n\n");
out.write("\t public "+ht_columnType.get(col.type)+" get"+abc2Abc(col.name)+"()\n");
out.write("\t {\n");
out.write("\t return "+col.name+";\n");
out.write("\t }\n");
}
}
void createColumnDeclare(Vector v_col,BufferedWriter out) throws Exception
{
for(int i=0;i<v_col.size();i++)
{
Column col=(Column)v_col.get(i);
out.write("\t private "+ht_columnType.get(col.type)+" "+col.name +";\n");
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -