From 6981868610af861b43db79cff73fa797e18b1e2f Mon Sep 17 00:00:00 2001 From: qi_liang Date: Tue, 16 Oct 2018 23:47:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=A1=A8=E5=88=9D=E5=A7=8B=E5=8C=96bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lq/code/util/sql/MysqlBuilder.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/lq/code/util/sql/MysqlBuilder.java b/src/main/java/com/lq/code/util/sql/MysqlBuilder.java index 73cf017..d012f8b 100644 --- a/src/main/java/com/lq/code/util/sql/MysqlBuilder.java +++ b/src/main/java/com/lq/code/util/sql/MysqlBuilder.java @@ -40,15 +40,17 @@ public class MysqlBuilder extends AbstractDbBuiler { } List tableList = JdbcUtils.getAllTable(); - Iterator
tableIterator = tableList.iterator(); - while (tableIterator.hasNext()){ - Table table = (Table) tableIterator.next(); + //初始化的时候,tableList可能为null + if(tableList!=null) { + Iterator
tableIterator = tableList.iterator(); + while (tableIterator.hasNext()) { + Table table = (Table) tableIterator.next(); if (map.containsKey(table.getTableName())) { Class clazz = map.get(table.getTableName()); Map clazzMap = new HashMap<>(); List fieldsList = BeanUtil.getAllField(clazz); Iterator fieldsIterator = fieldsList.iterator(); - while (fieldsIterator.hasNext()){ + while (fieldsIterator.hasNext()) { Field f = fieldsIterator.next(); clazzMap.put(SqlUtil.caseToHump(f.getName()), f); } @@ -64,7 +66,7 @@ public class MysqlBuilder extends AbstractDbBuiler { } columnIterator = columnList.iterator(); - while (columnIterator.hasNext()){ + while (columnIterator.hasNext()) { Column column = columnIterator.next(); sql.append("ALTER TABLE " + table.getTableName() + " DROP COLUMN " + column.getColumnName() + ";"); } @@ -86,8 +88,8 @@ public class MysqlBuilder extends AbstractDbBuiler { } map.remove(table.getTableName()); } + } } - for (String key : map.keySet()) { sql.append(this.createTableStr(map.get(key))); }