Prechádzať zdrojové kódy

fix(backend): AdminArticleController 空字串转Long抛NumberFormatException

- create/update 方法中 categoryId/readTime/difficultyLevel 字段
  防御性判空: 增加 !trim().isEmpty() 检查, 避免空字串  传入 Long.valueOf()
Xiaogang Liao 2 mesiacov pred
rodič
commit
cea34bf35e

+ 6 - 6
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/AdminArticleController.java

@@ -47,20 +47,20 @@ public class AdminArticleController {
         Article article = new Article();
         article.setTitle((String) body.get("title"));
         article.setContent((String) body.get("content"));
-        if (body.get("categoryId") != null) {
+        if (body.get("categoryId") != null && !body.get("categoryId").toString().trim().isEmpty()) {
             article.setCategoryId(Long.valueOf(body.get("categoryId").toString()));
         }
         article.setSummary((String) body.get("summary"));
         article.setCoverImage((String) body.get("coverImage"));
         article.setTags((String) body.get("tags"));
         article.setAuthor((String) body.get("author"));
-        if (body.get("readTime") != null) {
+        if (body.get("readTime") != null && !body.get("readTime").toString().trim().isEmpty()) {
             article.setReadTime(Integer.valueOf(body.get("readTime").toString()));
         }
         if (body.get("contentType") != null) {
             article.setContentType((String) body.get("contentType"));
         }
-        if (body.get("difficultyLevel") != null) {
+        if (body.get("difficultyLevel") != null && !body.get("difficultyLevel").toString().trim().isEmpty()) {
             article.setDifficultyLevel(Integer.valueOf(body.get("difficultyLevel").toString()));
         }
         // relatedDimensions may come as array from frontend
@@ -96,20 +96,20 @@ public class AdminArticleController {
         article.setId(articleId);
         article.setTitle((String) body.get("title"));
         article.setContent((String) body.get("content"));
-        if (body.get("categoryId") != null) {
+        if (body.get("categoryId") != null && !body.get("categoryId").toString().trim().isEmpty()) {
             article.setCategoryId(Long.valueOf(body.get("categoryId").toString()));
         }
         article.setSummary((String) body.get("summary"));
         article.setCoverImage((String) body.get("coverImage"));
         article.setTags((String) body.get("tags"));
         article.setAuthor((String) body.get("author"));
-        if (body.get("readTime") != null) {
+        if (body.get("readTime") != null && !body.get("readTime").toString().trim().isEmpty()) {
             article.setReadTime(Integer.valueOf(body.get("readTime").toString()));
         }
         if (body.get("contentType") != null) {
             article.setContentType((String) body.get("contentType"));
         }
-        if (body.get("difficultyLevel") != null) {
+        if (body.get("difficultyLevel") != null && !body.get("difficultyLevel").toString().trim().isEmpty()) {
             article.setDifficultyLevel(Integer.valueOf(body.get("difficultyLevel").toString()));
         }
         Object rd = body.get("relatedDimensions");