锋哥原创的Springboot+Layui python222网站实战:
/**
* 根据id查询帖子详细信息
* @param id
* @return
* @throws Exception
*/
@RequestMapping("/{id}")
public ModelAndView view(@PathVariable("id")Integer id)throws Exception{
Article article = articleService.getById(id);
if(article!=null && article.getStatus()!=2){
return null;
}else{
ModelAndView mav=new ModelAndView();
mav.setViewName("article");
mav.addObject("article",article);
return mav;
}
}
前端article.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title th:text="${article.title}+'-'+${application.propertyMap['k1']}"></title>
<meta name="keywords" th:content="${article.keyWords}">
<meta name="description" th:content="${article.title}">
<link href="/systemImages/favicon.ico" rel="SHORTCUT ICON">
<link rel="stylesheet" href="/static/layui/css/layui.css"/>
<link rel="stylesheet" href="/static/css/css.css"/>
<link rel="stylesheet" type="text/css" href="/static/css/normalize.css" />
<link rel="stylesheet" href="/static/css/font-awesome.min.css">
</head>
<body>
<div class="header_top" th:include="common/head::#h" />
<div class="header" th:include="common/menu::#m" />
<div class="main_wrapper">
<div class="w1220 index_content">
<div class="content_left">
<div class="article">
<div class="title" th:text="${article.title}"></div>
<div class="publishDateAndDownload">
<div class="publishDate" th:text="${'发布于:'+#dates.format(article.publishDate, 'yyyy-MM-dd HH:mm:ss')}"></div>
</div>
<div class="content" th:utext="${article.content}"></div>
<div class="downloadContent" th:if="${!article.download}" th:text="${'转载自:'+article.downloadContent}"></div>
</div>
</div>
<div class="content_right">
<div class="card">
<h4 class="card_title">热门帖子推荐</h4>
<ul class="item_list">
<li th:each="hotArticle,status:${application.hotArticleList.subList(0,10)}"><span class="number" th:text="${status.index+1}+'.'"></span><a th:href="'/article/'+${hotArticle.id}" target="_blank" th:title="${hotArticle.title}" th:text="${hotArticle.title}"></a></li>
</ul>
</div>
<div class="tag">
<h4 class="tag_title">热门标签推荐</h4>
<ul class="item_list">
<li th:each="tag:${application.tagList}">
<a th:href="@{'/search/1?keyWord='+${tag.name}}" target="_blank"><button type="button" class="layui-btn layui-btn-sm" th:text="${tag.name}"></button></a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="footer" th:include="common/footer::#f" />
</body>
</html>