之前是用markdown语法写博客,现在需要将博客展示
这里引入了thymeleaf模板
1. 编写ArticleController
@Autowired
ArticleService articleService;
@GetMapping("/article/showArticle/{articleId}")
public String showArticle(@PathVariable("articleId") int articleId,
HttpServletResponse response,
Model model,
HttpServletRequest request){
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//articleService.getArticleById()
Article article=articleService.getArticleById(articleId);
if(article!=null&&article.getTitle()!=null){
model.addAttribute("article",article);
}
response.setHeader("articleId",articleId+"");
return "showArticle";
}
2. 在ArticleService中实现了getArticleById函数
import java.util.List;
public interface ArticleService {
public List<Article> findAllArticle();
public List<Article> findUserArticle(int userid);
public Article getArticleById(int id);
public int createNewArticle(Article article);
public List<Article> getArticleList();
}
ArticleServerImpl.class是ArticleService的实现类
import com.nevergetme.nevergetmeweb.bean.Article;
import com.nevergetme.nevergetmeweb.mapper.ArticleMapper;
import com.nevergetme.nevergetmeweb.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ArticleServerImpl implements ArticleService {
@Autowired
private ArticleMapper articleMapper;
@Override
public