|
@@ -2,7 +2,6 @@ package com.firerock.webttkuaiban.demos.controller;
|
|
|
|
|
|
import com.firerock.webttkuaiban.demos.pojo.Article;
|
|
import com.firerock.webttkuaiban.demos.pojo.Article;
|
|
import com.firerock.webttkuaiban.demos.service.ArticleService;
|
|
import com.firerock.webttkuaiban.demos.service.ArticleService;
|
|
-import org.apache.tomcat.util.codec.binary.StringUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -25,35 +24,35 @@ public class ArticleTemplateController {
|
|
ArticleService articleService;
|
|
ArticleService articleService;
|
|
|
|
|
|
@GetMapping("/pageList/{pageIndex}") // 这里的 PageBean 是事先定义好的实体类
|
|
@GetMapping("/pageList/{pageIndex}") // 这里的 PageBean 是事先定义好的实体类
|
|
- public Object PageList(Model model, @PathVariable("pageIndex") Integer pageIndex, @RequestParam(required = false) String info)
|
|
|
|
- {
|
|
|
|
- Integer pageSize=10;
|
|
|
|
|
|
+ public Object PageList(Model model, @PathVariable("pageIndex") Integer pageIndex, @RequestParam(required = false) String info) {
|
|
|
|
+ Integer pageSize = 10;
|
|
// 定义格式化器
|
|
// 定义格式化器
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
- List<Article> articleList= articleService.PageList(pageIndex,pageSize,info);
|
|
|
|
- Integer total=articleService.getTotal(info);
|
|
|
|
- if (!articleList.isEmpty()){
|
|
|
|
|
|
+ List<Article> articleList = articleService.PageList(pageIndex, pageSize, info);
|
|
|
|
+ Integer total = articleService.getTotal(info);
|
|
|
|
+ if (!articleList.isEmpty()) {
|
|
for (Article article : articleList) {
|
|
for (Article article : articleList) {
|
|
byte[] imageData = article.getCoverImg();
|
|
byte[] imageData = article.getCoverImg();
|
|
- if (imageData != null){
|
|
|
|
|
|
+ if (imageData != null) {
|
|
String base64Image = Base64.getEncoder().encodeToString(imageData);
|
|
String base64Image = Base64.getEncoder().encodeToString(imageData);
|
|
article.setBaseImage(base64Image);
|
|
article.setBaseImage(base64Image);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
article.setBaseImage("");
|
|
article.setBaseImage("");
|
|
}
|
|
}
|
|
article.setCreateTimeStr(article.getCreateTime().format(formatter));
|
|
article.setCreateTimeStr(article.getCreateTime().format(formatter));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
model.addAttribute("knowledgeFieldTableList", articleList);
|
|
model.addAttribute("knowledgeFieldTableList", articleList);
|
|
- model.addAttribute("total",total );
|
|
|
|
|
|
+ model.addAttribute("total", total);
|
|
return "knowledge";
|
|
return "knowledge";
|
|
}
|
|
}
|
|
|
|
+
|
|
@RequestMapping(value = "/articleList", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/articleList", method = RequestMethod.GET)
|
|
public String articleList(Model model) {
|
|
public String articleList(Model model) {
|
|
List<HashMap> articles = new ArrayList<>();
|
|
List<HashMap> articles = new ArrayList<>();
|
|
for (int i = 0; i < 10; i++) {
|
|
for (int i = 0; i < 10; i++) {
|
|
HashMap<String, String> article = new HashMap<>();
|
|
HashMap<String, String> article = new HashMap<>();
|
|
- article.put("id", "" + (i+1));
|
|
|
|
|
|
+ article.put("id", "" + (i + 1));
|
|
article.put("title", "Article Title " + i);
|
|
article.put("title", "Article Title " + i);
|
|
article.put("content", "Article Content " + i);
|
|
article.put("content", "Article Content " + i);
|
|
articles.add(article);
|
|
articles.add(article);
|
|
@@ -61,36 +60,34 @@ public class ArticleTemplateController {
|
|
model.addAttribute("articles", articles);
|
|
model.addAttribute("articles", articles);
|
|
return "articleList";
|
|
return "articleList";
|
|
}
|
|
}
|
|
|
|
+
|
|
@GetMapping("/articleDetail/{id}") // 这里的 PageBean 是事先定义好的实体类
|
|
@GetMapping("/articleDetail/{id}") // 这里的 PageBean 是事先定义好的实体类
|
|
- public Object articleDetail(Model model,@PathVariable("id") Integer id)
|
|
|
|
- {
|
|
|
|
|
|
+ public Object articleDetail(Model model, @PathVariable("id") Integer id) {
|
|
// 定义格式化器
|
|
// 定义格式化器
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
long l = System.currentTimeMillis();
|
|
long l = System.currentTimeMillis();
|
|
- List<Article> latestList =articleService.latestList();
|
|
|
|
- if (!latestList.isEmpty()){
|
|
|
|
|
|
+ List<Article> latestList = articleService.latestList();
|
|
|
|
+ if (!latestList.isEmpty()) {
|
|
for (Article article : latestList) {
|
|
for (Article article : latestList) {
|
|
byte[] imageData = article.getCoverImg();
|
|
byte[] imageData = article.getCoverImg();
|
|
- if (imageData != null){
|
|
|
|
|
|
+ if (imageData != null) {
|
|
String base64Image = Base64.getEncoder().encodeToString(imageData);
|
|
String base64Image = Base64.getEncoder().encodeToString(imageData);
|
|
article.setBaseImage(base64Image);
|
|
article.setBaseImage(base64Image);
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
article.setBaseImage("");
|
|
article.setBaseImage("");
|
|
}
|
|
}
|
|
article.setCreateTimeStr(article.getCreateTime().format(formatter));
|
|
article.setCreateTimeStr(article.getCreateTime().format(formatter));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- List<Article> relatedList =articleService.relatedList(id);
|
|
|
|
- if (!relatedList.isEmpty()){
|
|
|
|
|
|
+ List<Article> relatedList = articleService.relatedList(id);
|
|
|
|
+ if (!relatedList.isEmpty()) {
|
|
for (Article article : relatedList) {
|
|
for (Article article : relatedList) {
|
|
byte[] imageData = article.getCoverImg();
|
|
byte[] imageData = article.getCoverImg();
|
|
- if (imageData != null){
|
|
|
|
|
|
+ if (imageData != null) {
|
|
String base64Image = Base64.getEncoder().encodeToString(imageData);
|
|
String base64Image = Base64.getEncoder().encodeToString(imageData);
|
|
article.setBaseImage(base64Image);
|
|
article.setBaseImage(base64Image);
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
article.setBaseImage("");
|
|
article.setBaseImage("");
|
|
}
|
|
}
|
|
article.setCreateTimeStr(article.getCreateTime().format(formatter));
|
|
article.setCreateTimeStr(article.getCreateTime().format(formatter));
|
|
@@ -102,9 +99,9 @@ public class ArticleTemplateController {
|
|
articleService.updateViewCountById(id);
|
|
articleService.updateViewCountById(id);
|
|
|
|
|
|
model.addAttribute("latestList", latestList);
|
|
model.addAttribute("latestList", latestList);
|
|
- model.addAttribute("relatedList",relatedList );
|
|
|
|
- model.addAttribute("article",article);
|
|
|
|
- model.addAttribute("categoryNameList",article.getCategoryNameList()==null?new ArrayList<String>():article.getCategoryNameList());
|
|
|
|
|
|
+ model.addAttribute("relatedList", relatedList);
|
|
|
|
+ model.addAttribute("article", article);
|
|
|
|
+ model.addAttribute("categoryNameList", article.getCategoryNameList() == null ? new ArrayList<String>() : article.getCategoryNameList());
|
|
return "knowledgeDetails";
|
|
return "knowledgeDetails";
|
|
}
|
|
}
|
|
}
|
|
}
|