Browse Source

null判断

zhou-hao 6 years ago
parent
commit
2a0dbf217e

+ 9 - 7
hsweb-commons/hsweb-commons-service/hsweb-commons-service-simple/src/main/java/org/hswebframework/web/service/GenericEntityService.java

@@ -112,13 +112,15 @@ public abstract class GenericEntityService<E extends GenericEntity<PK>, PK>
 
     @SuppressWarnings("unchecked")
     protected boolean dataExisted(E entity) {
-        try {
-            logicPrimaryKeyValidator.validate(entity);
-        } catch (DuplicateKeyException e) {
-            if (getEntityType().isInstance(e.getData())) {
-                PK id = ((E) e.getData()).getId();
-                entity.setId(id);
-                return true;
+        if (null != logicPrimaryKeyValidator) {
+            try {
+                logicPrimaryKeyValidator.validate(entity);
+            } catch (DuplicateKeyException e) {
+                if (getEntityType().isInstance(e.getData())) {
+                    PK id = ((E) e.getData()).getId();
+                    entity.setId(id);
+                    return true;
+                }
             }
         }
         return null != entity.getId() && null != selectByPk(entity.getId());