DESKTOP-8FESTBI\Administrator 8 kuukautta sitten
vanhempi
commit
6e4c8d4a24

+ 12
- 2
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/controller/CategoryController.java Näytä tiedosto

@@ -26,8 +26,18 @@ public class CategoryController extends BaseController {
26 26
 //    }
27 27
     @GetMapping("/tree")
28 28
     public AjaxResult tree() {
29
-        List<NovelCategory> categories = categoryService.getCategoryTree();
30
-        return AjaxResult.success(categories);
29
+//        List<NovelCategory> categories = categoryService.getCategoryTree();
30
+//        logger.info("成功获取分类树,数量: {}", categories.size());
31
+//        return AjaxResult.success(categories);
32
+
33
+        try {
34
+            List<NovelCategory> categories = categoryService.getCategoryTree();
35
+            logger.info("成功获取分类树,数量: {}", categories.size());
36
+            return AjaxResult.success(categories);
37
+        } catch (Exception e) {
38
+            logger.error("获取分类树失败", e);
39
+            return AjaxResult.error("获取分类失败");
40
+        }
31 41
     }
32 42
     // 获取分类树
33 43
 //    @GetMapping("/tree")

+ 22
- 2
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/domain/NovelCategory.java Näytä tiedosto

@@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import com.baomidou.mybatisplus.annotation.TableId;
5 5
 import com.baomidou.mybatisplus.annotation.TableName;
6
+import com.fasterxml.jackson.annotation.JsonIgnore;
6 7
 import com.fasterxml.jackson.annotation.JsonInclude;
7 8
 import lombok.Data;
8 9
 
@@ -34,9 +35,13 @@ public class NovelCategory {
34 35
     private String templateFilter;
35 36
     private String link;
36 37
     @TableField("create_time")
37
-    @JsonInclude(JsonInclude.Include.NON_NULL) // 忽略null字段
38
+    @JsonInclude(JsonInclude.Include.NON_NULL)
38 39
     private Integer createTime;
40
+    public Integer getCreateTime() {
41
+        return createTime;
42
+    }
39 43
     @TableField("update_time")
44
+    @JsonInclude(JsonInclude.Include.NON_NULL)
40 45
     private Integer updateTime;
41 46
     private Integer status;
42 47
     private Integer type;
@@ -46,7 +51,22 @@ public class NovelCategory {
46 51
     private List<NovelCategory> children;
47 52
 
48 53
     // 获取格式化创建时间
54
+//    public String getFormattedCreateTime() {
55
+//        return new SimpleDateFormat("yyyy-MM-dd").format(new Date(createTime * 1000L));
56
+//    }
57
+    // 安全的格式化方法
49 58
     public String getFormattedCreateTime() {
50
-        return new SimpleDateFormat("yyyy-MM-dd").format(new Date(createTime * 1000L));
59
+        return createTime != null ? formatTime(createTime) : "";
60
+    }
61
+
62
+    // 防止直接访问可能为null的原始字段
63
+    @JsonIgnore
64
+    public Integer getRawCreateTime() {
65
+        return createTime;
66
+    }
67
+    // 或者完全移除这个方法,如果不需要格式化输出
68
+    private String formatTime(Integer timestamp) {
69
+        // 实现你的时间格式化逻辑
70
+        return String.valueOf(timestamp);
51 71
     }
52 72
 }

Loading…
Peruuta
Tallenna