预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

1.与数据库建立连接 在DBUtil中设置数据库相关的参数 Class.forName(driverName); conn=DriverManager.getConnection(url,user,password); 2.获得数据库中的所有表 Mapmaps=newHashMap(); PreparedStatementpstate=conn.prepareStatement("showtablestatus"); ResultSetresults=pstate.executeQuery(); while(results.next()){ StringtableName=results.getString("NAME"); Stringcomment=results.getString("COMMENT"); maps.put(tableName,comment); } 3.获得每个表中的信息 封装一个实体来存储表中的信息 PreparedStatementpstate=conn.prepareStatement("showfullfieldsfrom"+tableName); ResultSetresults=pstate.executeQuery(); Listlists=newArrayList(); while(results.next()){ Columncolumn=newColumn(); Stringfield=results.getString("FIELD"); column.setFeildMapper(field); StringfieldName=processField(field); column.setFeild(fieldName); Stringtype=processType(results.getString("TYPE")); Stringcomment=results.getString("COMMENT"); column.setType(type); column.setComment(comment); lists.add(column); } 4.拼串输出 将固定代码中需要变动的字段从实体中取拼串写入文档中 例如给表生成po: publicclassWritePo{ publicstaticvoidcreatePo(Stringpath,StringpackageName,StringupTable,StringlowTable,Listcolumns)throwsIOException{ Filefolder=newFile(path+lowTable+"/po"); if(!folder.exists()){ folder.mkdirs(); } FilebeanFile=newFile(folder+"/"+upTable+".java"); BufferedWriterbw=newBufferedWriter(newOutputStreamWriter( newFileOutputStream(beanFile))); bw.write("package"+packageName+lowTable+".po;"); bw.newLine(); bw.write("importjava.io.Serializable;"); bw.newLine(); //bw.write("importlombok.Data;"); //bw.write("importjavax.persistence.Entity;"); bw.newLine(); bw.write("@SuppressWarnings(\"serial\")"); bw.newLine(); //bw.write("@Entity"); //bw.write("@Data"); //bw.newLine(); bw.write("publicclass"+upTable+"implementsSerializable{"); bw.newLine(); bw.newLine(); intsize=columns.size(); for(Columnvo:columns){ //bw.write("\t/**"+comments.get(i)+"**/"); bw.write("\t/**"); bw.newLine(); bw.write("\t*"+vo.getComment()); bw.newLine(); bw.write("\t**/"); bw.newLine(); bw.write("\tprivate"+vo.getType()+""+vo.getFeild()+";"); bw.newLi