From 77295cd68cb4674453d846ca81559af1574ed30f Mon Sep 17 00:00:00 2001 From: yangfuhai Date: Thu, 3 May 2018 10:04:51 +0800 Subject: [PATCH] jboot v1.4.9 release --- .../java/io/jboot/db/model/JbootModel.java | 23 ++++++++++--------- src/test/java/JsonTest.java | 1 - 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/jboot/db/model/JbootModel.java b/src/main/java/io/jboot/db/model/JbootModel.java index c173eb119..6000f2679 100644 --- a/src/main/java/io/jboot/db/model/JbootModel.java +++ b/src/main/java/io/jboot/db/model/JbootModel.java @@ -118,10 +118,7 @@ public M copyModel() { M m = null; try { m = (M) _getUsefulClass().newInstance(); - Table table = _getTable(); - if (table == null) { - throw new JbootException("can't get table of " + _getUsefulClass() + " , maybe config incorrect"); - } + Table table = _getTable(true); Set attrKeys = table.getColumnTypeMap().keySet(); for (String attrKey : attrKeys) { Object o = this.get(attrKey); @@ -597,16 +594,20 @@ public Page paginateByColumns(int pageNumber, int pageSize, List colu protected String _getTableName() { - return _getTable().getName(); + return _getTable(true).getName(); } - private transient Table table; protected Table _getTable() { + return _getTable(false); + } + + private transient Table table; + protected Table _getTable(boolean validateNull) { if (table == null) { table = super._getTable(); - if (table == null) { - throw new JbootException(String.format("table of class %s is null, maybe cannot connection to database or not use correct datasource, " + + if (table == null && validateNull) { + throw new JbootException(String.format("class %s can not mapping to database table, maybe cannot connection to database or not use correct datasource, " + "please check jboot.properties or correct config @Table(datasource=xxx) if you use multi datasource.", _getUsefulClass().getName())); } } @@ -620,7 +621,7 @@ protected String _getPrimaryKey() { if (primaryKey != null) { return primaryKey; } - String[] primaryKeys = _getTable().getPrimaryKey(); + String[] primaryKeys = _getTable(true).getPrimaryKey(); if (null != primaryKeys && primaryKeys.length == 1) { primaryKey = primaryKeys[0]; } @@ -633,14 +634,14 @@ protected String _getPrimaryKey() { protected Class _getPrimaryType() { if (primaryType == null) { - primaryType = _getTable().getColumnType(_getPrimaryKey()); + primaryType = _getTable(true).getColumnType(_getPrimaryKey()); } return primaryType; } protected boolean hasColumn(String columnLabel) { - return _getTable().hasColumnLabel(columnLabel); + return _getTable(true).hasColumnLabel(columnLabel); } // -----------------------------Override---------------------------- diff --git a/src/test/java/JsonTest.java b/src/test/java/JsonTest.java index 3e34af95d..f50f7d84f 100644 --- a/src/test/java/JsonTest.java +++ b/src/test/java/JsonTest.java @@ -24,7 +24,6 @@ public void testJFinalJson() { user1.setId(100); user1.setName(null); - String json1 = JFinalJson.getJson().toJson(user1); System.out.println(json1);