|
@@ -1,10 +1,97 @@
|
|
|
package com.firerock.webttkuaiban.demos.controller;
|
|
|
|
|
|
+import com.firerock.webttkuaiban.demos.pojo.Article;
|
|
|
+import com.firerock.webttkuaiban.demos.service.ArticleService;
|
|
|
+import org.apache.tomcat.util.codec.binary.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.ui.Model;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Base64;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("articleTemplate")
|
|
|
public class ArticleTemplateController {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ArticleService articleService;
|
|
|
+
|
|
|
+ @GetMapping("/pageList") // 这里的 PageBean 是事先定义好的实体类
|
|
|
+ public Object PageList(Model model, Integer pageIndex, Integer pageSize,
|
|
|
+ @RequestParam(required = false) String info)
|
|
|
+ {
|
|
|
+ List<Article> articleList= articleService.PageList(pageIndex,pageSize,info);
|
|
|
+ Integer total=articleService.getTotal(info);
|
|
|
+ if (!articleList.isEmpty()){
|
|
|
+ for (Article article : articleList) {
|
|
|
+ byte[] imageData = article.getCoverImg();
|
|
|
+ if (imageData != null){
|
|
|
+ String base64Image = Base64.getEncoder().encodeToString(imageData);
|
|
|
+ article.setBaseImage(base64Image);
|
|
|
+ }else {
|
|
|
+ article.setBaseImage("");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ model.addAttribute("knowledgeFieldTableList", articleList);
|
|
|
+ model.addAttribute("total",total );
|
|
|
+ return "knowledgeField";
|
|
|
+ }
|
|
|
+ @RequestMapping(value = "/articleList", method = RequestMethod.GET)
|
|
|
+ public String articleList(Model model) {
|
|
|
+ List<HashMap> articles = new ArrayList<>();
|
|
|
+ for (int i = 0; i < 10; i++) {
|
|
|
+ HashMap<String, String> article = new HashMap<>();
|
|
|
+ article.put("id", "" + (i+1));
|
|
|
+ article.put("title", "Article Title " + i);
|
|
|
+ article.put("content", "Article Content " + i);
|
|
|
+ articles.add(article);
|
|
|
+ }
|
|
|
+ model.addAttribute("articles", articles);
|
|
|
+ return "articleList";
|
|
|
+ }
|
|
|
+ @GetMapping("/articleDetail") // 这里的 PageBean 是事先定义好的实体类
|
|
|
+ public Object articleDetail(Model model,@RequestParam("id") Integer id)
|
|
|
+ {
|
|
|
+ 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("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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 article = articleService.getArticleById(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 "knowledgeField";
|
|
|
+ }
|
|
|
}
|