DESKTOP-8FESTBI\Administrator 8 ay önce
ebeveyn
işleme
6e4c8d4a24

+ 12
- 2
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/controller/CategoryController.java Dosyayı Görüntüle

26
 //    }
26
 //    }
27
     @GetMapping("/tree")
27
     @GetMapping("/tree")
28
     public AjaxResult tree() {
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
 //    @GetMapping("/tree")
43
 //    @GetMapping("/tree")

+ 22
- 2
RuoYi-Vue/ruoyi-system/src/main/java/com/ruoyi/novel/domain/NovelCategory.java Dosyayı Görüntüle

3
 import com.baomidou.mybatisplus.annotation.IdType;
3
 import com.baomidou.mybatisplus.annotation.IdType;
4
 import com.baomidou.mybatisplus.annotation.TableId;
4
 import com.baomidou.mybatisplus.annotation.TableId;
5
 import com.baomidou.mybatisplus.annotation.TableName;
5
 import com.baomidou.mybatisplus.annotation.TableName;
6
+import com.fasterxml.jackson.annotation.JsonIgnore;
6
 import com.fasterxml.jackson.annotation.JsonInclude;
7
 import com.fasterxml.jackson.annotation.JsonInclude;
7
 import lombok.Data;
8
 import lombok.Data;
8
 
9
 
34
     private String templateFilter;
35
     private String templateFilter;
35
     private String link;
36
     private String link;
36
     @TableField("create_time")
37
     @TableField("create_time")
37
-    @JsonInclude(JsonInclude.Include.NON_NULL) // 忽略null字段
38
+    @JsonInclude(JsonInclude.Include.NON_NULL)
38
     private Integer createTime;
39
     private Integer createTime;
40
+    public Integer getCreateTime() {
41
+        return createTime;
42
+    }
39
     @TableField("update_time")
43
     @TableField("update_time")
44
+    @JsonInclude(JsonInclude.Include.NON_NULL)
40
     private Integer updateTime;
45
     private Integer updateTime;
41
     private Integer status;
46
     private Integer status;
42
     private Integer type;
47
     private Integer type;
46
     private List<NovelCategory> children;
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
     public String getFormattedCreateTime() {
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…
İptal
Kaydet