CMS静态化后的动态数据刷新
This commit is contained in:
@@ -4,37 +4,27 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.cmsfront.web;
|
package com.jeesite.modules.cmsfront.web;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
import com.jeesite.common.collect.ListUtils;
|
import com.jeesite.common.collect.ListUtils;
|
||||||
import com.jeesite.common.config.Global;
|
import com.jeesite.common.config.Global;
|
||||||
import com.jeesite.common.entity.Page;
|
import com.jeesite.common.entity.Page;
|
||||||
import com.jeesite.common.lang.ObjectUtils;
|
import com.jeesite.common.lang.ObjectUtils;
|
||||||
import com.jeesite.common.lang.StringUtils;
|
import com.jeesite.common.lang.StringUtils;
|
||||||
import com.jeesite.common.web.BaseController;
|
import com.jeesite.common.web.BaseController;
|
||||||
import com.jeesite.modules.cms.entity.Article;
|
import com.jeesite.modules.cms.entity.*;
|
||||||
import com.jeesite.modules.cms.entity.ArticleData;
|
|
||||||
import com.jeesite.modules.cms.entity.Category;
|
|
||||||
import com.jeesite.modules.cms.entity.Comment;
|
|
||||||
import com.jeesite.modules.cms.entity.Site;
|
|
||||||
import com.jeesite.modules.cms.service.ArticleService;
|
import com.jeesite.modules.cms.service.ArticleService;
|
||||||
import com.jeesite.modules.cms.service.CategoryService;
|
import com.jeesite.modules.cms.service.CategoryService;
|
||||||
import com.jeesite.modules.cms.service.CommentService;
|
import com.jeesite.modules.cms.service.CommentService;
|
||||||
import com.jeesite.modules.cms.utils.CmsUtils;
|
import com.jeesite.modules.cms.utils.CmsUtils;
|
||||||
import com.jeesite.modules.sys.utils.ValidCodeUtils;
|
import com.jeesite.modules.sys.utils.ValidCodeUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网站Controller
|
* 网站Controller
|
||||||
@@ -274,9 +264,6 @@ public class FrontController extends BaseController {
|
|||||||
return "error/404";
|
return "error/404";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文章阅读次数+1
|
|
||||||
articleService.updateHitsAddOne(contentId);
|
|
||||||
|
|
||||||
// 如果设置了外部链接,则跳转到指定链接
|
// 如果设置了外部链接,则跳转到指定链接
|
||||||
if (StringUtils.isNotBlank(article.getHref())) {
|
if (StringUtils.isNotBlank(article.getHref())) {
|
||||||
if (article.getHref().startsWith(request.getContextPath())) {
|
if (article.getHref().startsWith(request.getContextPath())) {
|
||||||
@@ -307,6 +294,16 @@ public class FrontController extends BaseController {
|
|||||||
return "error/404";
|
return "error/404";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文章读取次数并加一
|
||||||
|
*/
|
||||||
|
@RequestMapping(value = { "article-hits-{articleId}" })
|
||||||
|
@ResponseBody
|
||||||
|
public long articleHits(@PathVariable String articleId) {
|
||||||
|
articleService.updateHitsAddOne(articleId);
|
||||||
|
return articleService.getHits(articleId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内容评论
|
* 内容评论
|
||||||
*/
|
*/
|
||||||
@@ -347,12 +344,12 @@ public class FrontController extends BaseController {
|
|||||||
comment.setStatus(isAudit ? Comment.STATUS_AUDIT : Comment.STATUS_NORMAL);
|
comment.setStatus(isAudit ? Comment.STATUS_AUDIT : Comment.STATUS_NORMAL);
|
||||||
comment.setStatus(Comment.STATUS_AUDIT);
|
comment.setStatus(Comment.STATUS_AUDIT);
|
||||||
commentService.save(comment);
|
commentService.save(comment);
|
||||||
return "{result:1, message:'提交成功" + (isAudit ? ",请等待审核" : "") + "。'}";
|
return renderResult("1", "提交成功" + (isAudit ? ",请等待审核" : "") + "。");
|
||||||
} else {
|
} else {
|
||||||
return "{result:2, message:'验证码不正确。'}";
|
return renderResult("2", "验证码不正确。");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "{result:2, message:'验证码不能为空。'}";
|
return renderResult("2", "验证码不能为空。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,19 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="updateExpiredWeight">
|
<update id="updateExpiredWeight">
|
||||||
update ${_prefix}cms_article SET weight = 0
|
UPDATE ${_prefix}cms_article SET weight = 0
|
||||||
WHERE weight > 0 AND weight_date < #{weightDate}
|
WHERE weight > 0 AND weight_date < #{weightDate}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="updateHitsAddOne">
|
<update id="updateHitsAddOne">
|
||||||
update ${_prefix}cms_article set
|
UPDATE ${_prefix}cms_article SET
|
||||||
hits = hits + 1
|
hits = hits + 1
|
||||||
WHERE id = #{id}
|
WHERE id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<select id="getHits" resultType="long">
|
||||||
|
SELECT hits FROM ${_prefix}cms_article
|
||||||
|
WHERE id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<ul class="article-list">
|
<ul class="article-list">
|
||||||
<#html:foreach items="${articleList(site.siteCode, category.categoryCode, 5)}" var="article,status">
|
<#html:foreach items="${articleList(site.siteCode, category.categoryCode, 5)}" var="article,status">
|
||||||
<li>${status.index}. <span class="pull-right">${article.updateDate,'yyyy-MM-dd'}</span>
|
<li>${status.index}. <span class="pull-right">${article.updateDate,'yyyy-MM-dd'}</span>
|
||||||
<a href="${article.url}" style="color:${article.color}">${abbr(article.title,28)}</a> </li>
|
<a href="${article.url}" style="color:${article.color}">${abbr(article.title,28)}</a></li>
|
||||||
</#html:foreach>
|
</#html:foreach>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
* @param bodyClass body标签的class内容
|
* @param bodyClass body标签的class内容
|
||||||
*/
|
*/
|
||||||
%>
|
%>
|
||||||
<!DOCTYPE html><html><head>
|
<% print('<'+'!DOC'+'TYPE html'+'>'); %><html><head>
|
||||||
<% include('../include/head.html', {title: text(title!)}){} %>
|
<% include('../include/head.html', {title: text(title!)}){} %>
|
||||||
</head><body class="${bodyClass!}">
|
</head><body class="${bodyClass!}">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<% include('../include/header.html'){} %>
|
<% include('../include/header.html'){}
|
||||||
${layoutContent}
|
%>${layoutContent}<%
|
||||||
<% include('../include/footer.html'){} %>
|
include('../include/footer.html'){} %>
|
||||||
</div>
|
</div>
|
||||||
@@ -19,13 +19,12 @@
|
|||||||
</#html:foreach>
|
</#html:foreach>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="pagination">${@page.toHtml()}</div>
|
<div class="pagination">${@page.toHtml()}</div>
|
||||||
<script type="text/javascript">
|
<script>
|
||||||
function page(n,s){
|
function page(n, s){
|
||||||
location="${category.url}?pageNo="+n+"&pageSize="+s;
|
location = "${category.url}?pageNo=" + n + "&pageSize=" + s;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</#html:if>
|
</#html:if>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<ul class="article-list">
|
<ul class="article-list">
|
||||||
<#html:foreach items="${articleList(site.siteCode, category.categoryCode, 5)}" var="article,status">
|
<#html:foreach items="${articleList(site.siteCode, category.categoryCode, 5)}" var="article,status">
|
||||||
<li>${status.index}. <span class="pull-right">${article.updateDate,'yyyy-MM-dd'}</span>
|
<li>${status.index}. <span class="pull-right">${article.updateDate,'yyyy-MM-dd'}</span>
|
||||||
<a href="${article.url}" style="color:${article.color}">${abbr(article.title,28)}</a> </li>
|
<a href="${article.url}" style="color:${article.color}">${abbr(article.title,28)}</a></li>
|
||||||
</#html:foreach>
|
</#html:foreach>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -38,4 +38,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,27 @@
|
|||||||
<% layout('layouts/default.html', {title:'文章查看',libs: []}){ %>
|
<% layout('layouts/default.html', {title:'文章查看',libs: []}){ %>
|
||||||
<% include('include/banner.html'){} %>
|
<% include('include/banner.html'){} %>
|
||||||
<div class="row main article-view">
|
<div class="row main article-view">
|
||||||
<h3 class="article-title">${article.title}</h3>
|
<h3 class="article-title">
|
||||||
<blockquote class="article-desc">摘要:${article.description}</blockquote>
|
${article.title}
|
||||||
<div class="article-content uparse">${article.articleData.content}</div>
|
</h3>
|
||||||
<div class="article-info">发布者:${article.createBy} 点击数:${article.hits} 发布时间:${article.createDate,"yyyy-MM-dd HH:mm"} 更新时间:${article.updateDate,"yyyy-MM-dd HH:mm"}</div>
|
<blockquote class="article-desc">
|
||||||
|
摘要:${article.description}
|
||||||
|
</blockquote>
|
||||||
|
<div class="article-content uparse">
|
||||||
|
${article.articleData.content}
|
||||||
|
</div>
|
||||||
|
<div class="article-info">
|
||||||
|
发布者:${article.createBy}
|
||||||
|
点击数:<span id="articleHits">~</span>
|
||||||
|
发布时间:${article.createDate,"yyyy-MM-dd HH:mm"}
|
||||||
|
更新时间:${article.updateDate,"yyyy-MM-dd HH:mm"}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<script>
|
||||||
|
$(function (){
|
||||||
|
$.get('${ctx}/article-hits-${article.id}', function(data){
|
||||||
|
$('#articleHits').html(data);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user