Ver Fonte

兼容id参数模式,谷歌已经抓取到了

QuYueTing há 6 meses atrás
pai
commit
0b996b9185

+ 44 - 0
fhKeeper/formulahousekeeper/webttkuaiban/src/main/java/com/firerock/webttkuaiban/demos/controller/ArticleTemplateController.java

@@ -104,4 +104,48 @@ public class ArticleTemplateController {
         model.addAttribute("categoryNameList", article.getCategoryNameList() == null ? new ArrayList<String>() : article.getCategoryNameList());
         return "knowledgeDetails";
     }
+
+    @GetMapping("/articleDetail")  // 这里的 PageBean 是事先定义好的实体类
+    public Object articleDetailById(Model model, @RequestParam Integer id) {
+        // 定义格式化器
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
+        long l = System.currentTimeMillis();
+        List<Article> latestList = articleService.latestList();
+        if (!latestList.isEmpty()) {
+            for (Article article : latestList) {
+                byte[] imageData = article.getCoverImg();
+                if (imageData != null) {
+                    String base64Image = Base64.getEncoder().encodeToString(imageData);
+                    article.setBaseImage(base64Image);
+                } else {
+                    article.setBaseImage("");
+                }
+                article.setCreateTimeStr(article.getCreateTime().format(formatter));
+            }
+        }
+        List<Article> relatedList = articleService.relatedList(id);
+        if (!relatedList.isEmpty()) {
+            for (Article article : relatedList) {
+                byte[] imageData = article.getCoverImg();
+                if (imageData != null) {
+                    String base64Image = Base64.getEncoder().encodeToString(imageData);
+                    article.setBaseImage(base64Image);
+                } else {
+                    article.setBaseImage("");
+                }
+                article.setCreateTimeStr(article.getCreateTime().format(formatter));
+            }
+        }
+        Article article = articleService.getArticleById(id);
+        article.setCreateTimeStr(article.getCreateTime().format(formatter));
+
+        articleService.updateViewCountById(id);
+
+        model.addAttribute("latestList", latestList);
+        model.addAttribute("relatedList", relatedList);
+        model.addAttribute("article", article);
+        model.addAttribute("categoryNameList", article.getCategoryNameList() == null ? new ArrayList<String>() : article.getCategoryNameList());
+        return "knowledgeDetails";
+    }
 }