diff --git a/modules/cms/src/main/java/com/jeesite/modules/cmsfront/web/FrontController.java b/modules/cms/src/main/java/com/jeesite/modules/cmsfront/web/FrontController.java index 3fb1e764..a4bf5b6f 100644 --- a/modules/cms/src/main/java/com/jeesite/modules/cmsfront/web/FrontController.java +++ b/modules/cms/src/main/java/com/jeesite/modules/cmsfront/web/FrontController.java @@ -4,37 +4,27 @@ */ 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.config.Global; import com.jeesite.common.entity.Page; import com.jeesite.common.lang.ObjectUtils; import com.jeesite.common.lang.StringUtils; import com.jeesite.common.web.BaseController; -import com.jeesite.modules.cms.entity.Article; -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.entity.*; import com.jeesite.modules.cms.service.ArticleService; import com.jeesite.modules.cms.service.CategoryService; import com.jeesite.modules.cms.service.CommentService; import com.jeesite.modules.cms.utils.CmsUtils; 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 @@ -274,9 +264,6 @@ public class FrontController extends BaseController { return "error/404"; } - // 文章阅读次数+1 - articleService.updateHitsAddOne(contentId); - // 如果设置了外部链接,则跳转到指定链接 if (StringUtils.isNotBlank(article.getHref())) { if (article.getHref().startsWith(request.getContextPath())) { @@ -307,6 +294,16 @@ public class FrontController extends BaseController { 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(Comment.STATUS_AUDIT); commentService.save(comment); - return "{result:1, message:'提交成功" + (isAudit ? ",请等待审核" : "") + "。'}"; + return renderResult("1", "提交成功" + (isAudit ? ",请等待审核" : "") + "。"); } else { - return "{result:2, message:'验证码不正确。'}"; + return renderResult("2", "验证码不正确。"); } } else { - return "{result:2, message:'验证码不能为空。'}"; + return renderResult("2", "验证码不能为空。"); } } diff --git a/modules/cms/src/main/resources/mappings/modules/cms/ArticleDao.xml b/modules/cms/src/main/resources/mappings/modules/cms/ArticleDao.xml index 5630e137..228098cd 100644 --- a/modules/cms/src/main/resources/mappings/modules/cms/ArticleDao.xml +++ b/modules/cms/src/main/resources/mappings/modules/cms/ArticleDao.xml @@ -21,14 +21,19 @@ - update ${_prefix}cms_article SET weight = 0 + UPDATE ${_prefix}cms_article SET weight = 0 WHERE weight > 0 AND weight_date < #{weightDate} - update ${_prefix}cms_article set + UPDATE ${_prefix}cms_article SET hits = hits + 1 - WHERE id = #{id} + WHERE id = #{id} + + \ No newline at end of file diff --git a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/include/footer.html b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/include/footer.html index 1d342d98..db770ef6 100644 --- a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/include/footer.html +++ b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/include/footer.html @@ -13,4 +13,4 @@ - + \ No newline at end of file diff --git a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/index.html b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/index.html index b71e1957..2d2e0cad 100644 --- a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/index.html +++ b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/index.html @@ -21,7 +21,7 @@ diff --git a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/layouts/default.html b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/layouts/default.html index d196faea..41ff7fbb 100644 --- a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/layouts/default.html +++ b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/layouts/default.html @@ -6,11 +6,11 @@ * @param bodyClass body标签的class内容 */ %> - +<% print('<'+'!DOC'+'TYPE html'+'>'); %> <% include('../include/head.html', {title: text(title!)}){} %>
-<% include('../include/header.html'){} %> -${layoutContent} -<% include('../include/footer.html'){} %> +<% include('../include/header.html'){} + %>${layoutContent}<% +include('../include/footer.html'){} %>
\ No newline at end of file diff --git a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/list.html b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/list.html index 4df90562..8bbba4d0 100644 --- a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/list.html +++ b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/list.html @@ -19,13 +19,12 @@ - <% } %> - diff --git a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/listCategory.html b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/listCategory.html index 67d67c2d..5c8a9eac 100644 --- a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/listCategory.html +++ b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/listCategory.html @@ -24,7 +24,7 @@ @@ -38,4 +38,3 @@ <% } %> - diff --git a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/viewArticle.html b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/viewArticle.html index c725fea7..27ba69cd 100644 --- a/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/viewArticle.html +++ b/modules/cms/src/main/resources/views/modules/cmsfront/themes/default/viewArticle.html @@ -1,9 +1,27 @@ <% layout('layouts/default.html', {title:'文章查看',libs: []}){ %> <% include('include/banner.html'){} %>
-

${article.title}

-
摘要:${article.description}
-
${article.articleData.content}
-
发布者:${article.createBy}   点击数:${article.hits}   发布时间:${article.createDate,"yyyy-MM-dd HH:mm"}   更新时间:${article.updateDate,"yyyy-MM-dd HH:mm"}
+

+ ${article.title} +

+
+ 摘要:${article.description} +
+
+ ${article.articleData.content} +
+
+ 发布者:${article.createBy}   + 点击数:~   + 发布时间:${article.createDate,"yyyy-MM-dd HH:mm"}   + 更新时间:${article.updateDate,"yyyy-MM-dd HH:mm"} +
<% } %> +