From a1b89a6b44c4312350d35c4aa053ed69c450c6f7 Mon Sep 17 00:00:00 2001 From: meng <154040976@qq.com> Date: Sat, 24 Nov 2018 13:56:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=85=E8=AF=BB=E6=8E=92=E8=A1=8C=E6=A6=9C?= =?UTF-8?q?=20=20=20=20=20=20=20=20=20=20=20--=E5=90=AC=E4=B8=80=E9=A6=96?= =?UTF-8?q?=E6=AD=8C=EF=BC=8C=E5=9B=9E=E5=BF=86=E4=B8=80=E6=AE=B5=E5=BE=80?= =?UTF-8?q?=E4=BA=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/len/controller/ArticleController.java | 24 +++++++++++++++++++ .../service/impl/BlogArticleServiceImpl.java | 9 +++++-- .../resources/mapper/BlogArticleMapper.xml | 1 + .../src/main/java/com/len/util/ReType.java | 3 +++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/len-blog/src/main/java/com/len/controller/ArticleController.java b/len-blog/src/main/java/com/len/controller/ArticleController.java index 9676bab..3be6821 100644 --- a/len-blog/src/main/java/com/len/controller/ArticleController.java +++ b/len-blog/src/main/java/com/len/controller/ArticleController.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import tk.mybatis.mapper.entity.Condition; import javax.servlet.http.HttpServletRequest; import java.text.SimpleDateFormat; @@ -96,6 +97,14 @@ public class ArticleController { return articleService.detail(code, ip); } + /** + * 根据标签code获取文章 + * + * @param tagName + * @param page + * @param limit + * @return + */ @GetMapping("/article/list/{tagName}") public ReType getArticleByTag(@PathVariable("tagName") String tagName, Integer page, Integer limit) { limit = limit > 100 ? 100 : limit; @@ -104,4 +113,19 @@ public class ArticleController { List articles = articleService.selectArticleByTag(tagName); return new ReType(startPage.getTotal(), startPage.getPageNum(), articles); } + + @GetMapping("/article/list/order/read") + public ReType getArticleByReadNumber() { + Condition condition = new Condition(BlogArticle.class); + PageHelper.startPage(1, 5); + condition.createCriteria(); + condition.orderBy("readNumber").desc(); + List articles = articleService.selectByExample(condition); + articles.forEach(s -> { + s.setContent(null); + }); + ReType reType = new ReType(); + reType.setData(articles); + return reType; + } } diff --git a/len-blog/src/main/java/com/len/service/impl/BlogArticleServiceImpl.java b/len-blog/src/main/java/com/len/service/impl/BlogArticleServiceImpl.java index 740a34b..4215077 100644 --- a/len-blog/src/main/java/com/len/service/impl/BlogArticleServiceImpl.java +++ b/len-blog/src/main/java/com/len/service/impl/BlogArticleServiceImpl.java @@ -108,7 +108,10 @@ public class BlogArticleServiceImpl extends BaseServiceImpl } BlogArticle blogArticle = detail.getArticle(); //点击次数 - addArticleReadNum(ip, blogArticle.getId()); + int clickNum = addArticleReadNum(ip, blogArticle.getId()); + if (clickNum > 0) { + blogArticle.setReadNumber(clickNum); + } //上一篇 PageHelper.startPage(1, 1); @@ -157,7 +160,7 @@ public class BlogArticleServiceImpl extends BaseServiceImpl * @param ip 访问者ip * @param articleId 文章id */ - private void addArticleReadNum(String ip, String articleId) { + private int addArticleReadNum(String ip, String articleId) { String str = ip + "_" + articleId; if (!StringUtils.isBlank(str)) { if (StringUtils.isEmpty(redisService.get(str))) { @@ -165,7 +168,9 @@ public class BlogArticleServiceImpl extends BaseServiceImpl BlogArticle article = selectByPrimaryKey(articleId); article.setReadNumber(article.getReadNumber() + 1); updateByPrimaryKey(article); + return article.getReadNumber(); } } + return -1; } } diff --git a/len-blog/src/main/resources/mapper/BlogArticleMapper.xml b/len-blog/src/main/resources/mapper/BlogArticleMapper.xml index 6ed8654..dfbc54b 100644 --- a/len-blog/src/main/resources/mapper/BlogArticleMapper.xml +++ b/len-blog/src/main/resources/mapper/BlogArticleMapper.xml @@ -65,6 +65,7 @@ bat.tag_id=bt.id where bt.tag_code=#{tagCode} + order by ba.top_num desc,ba.create_date desc