package com.taover.business; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Properties; import com.taover.base.template.model.bussiness.EnvironmentModel; import com.taover.db.Tools; import com.taover.tools.StringUtil; public class GenerateCS { public static void main(String[] args) throws Exception{ //读取配置文件 Properties properties = Tools.getProperties(); //取数据库连接 Connection conn = Tools.getConnection(properties); //初始化要生成的表列表 List tableNameList = new ArrayList(); String schameName = properties.getProperty("SchameName"); String createSchame = properties.getProperty("CreateSchame"); String dbType = properties.getProperty("dbtype"); String tableName = properties.getProperty("TableName"); if("mysql".equalsIgnoreCase(dbType)){ //schameName = schameName.toUpperCase(); } if (createSchame.equalsIgnoreCase("true") || "ALL".equalsIgnoreCase(tableName) ) { String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '"+schameName+"'"; ResultSet rs = Tools.executeQuery(Tools.createStmt(conn), sql); if (null == rs) return ; try { while (rs.next()) { tableNameList.add(rs.getString("Table_name")); } } catch (SQLException e) { e.printStackTrace(); } Tools.close(rs); } else { if("mysql".equalsIgnoreCase(dbType)){ tableName = tableName.toUpperCase(); } String[] TableNameArr = tableName.split(","); for (int i = 0; i < TableNameArr.length; i++) tableNameList.add(TableNameArr[i]); } //读取配置文件信息 String modulePackageInfo = properties.getProperty("modulePackageInfo"); String moduleFilePath = properties.getProperty("moduleFilePath"); String dbPackageInfo = properties.getProperty("dbPackageInfo"); //循环遍历各个表名 for (int i = 0; i < tableNameList.size(); i++) { String tableNameCurr = (String) tableNameList.get(i); String beanClassName = StringUtil.formatBeanNameFirstUpper(tableNameCurr); String poPackageInfo = dbPackageInfo + "." + beanClassName.toLowerCase(); EnvironmentModel envir = EnvironmentModel.createEnvironmentModel( modulePackageInfo, moduleFilePath, poPackageInfo, beanClassName); //生成Controller层 GenerateController.generateController(envir, false); //生成Service层 GenerateService.generateService(envir, false); System.out.println(tableNameCurr + " : 生成结束"); } conn.close(); System.out.println("全部结束"); } }