From b5fd862b652bdabc643e73f1913a4115cc5d27e0 Mon Sep 17 00:00:00 2001 From: johnniang Date: Tue, 2 Apr 2019 18:40:15 +0800 Subject: [PATCH] Add some default value before persisting --- .../cc/ryanc/halo/model/entity/BasePost.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/main/java/cc/ryanc/halo/model/entity/BasePost.java b/src/main/java/cc/ryanc/halo/model/entity/BasePost.java index 9fa6a7e3d..e8777246c 100644 --- a/src/main/java/cc/ryanc/halo/model/entity/BasePost.java +++ b/src/main/java/cc/ryanc/halo/model/entity/BasePost.java @@ -122,8 +122,49 @@ public class BasePost extends BaseEntity { @Override public void prePersist() { super.prePersist(); + id = null; editTime = getCreateTime(); + + if (status == null) { + status = PostStatus.DRAFT; + } + + if (summary == null) { + summary = ""; + } + + if (thumbnail == null) { + thumbnail = ""; + } + + if (visits == null) { + visits = 0L; + } + + if (disallowComment == null) { + disallowComment = false; + } + + if (password == null) { + password = ""; + } + + if (template == null) { + template = ""; + } + + if (topPriority == null) { + topPriority = 0; + } + + if (createFrom == null) { + createFrom = PostCreateFrom.ADMIN; + } + + if (likes == null) { + likes = 0L; + } } }