From f41e478a66b27ddf1c1bac619d59217bc22404db Mon Sep 17 00:00:00 2001 From: sjm <2431685932@qq.com> Date: Fri, 7 Jul 2023 00:16:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=8F=91=E5=B8=83=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hellogithub/service/articleService.java | 29 +++++++++++++++++++ .../servlet/article/ArticlePublish.java | 6 ++-- .../servlet/userDetailServlet.java | 4 +++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/com/hellogithub/service/articleService.java b/src/com/hellogithub/service/articleService.java index bd9a11d..7e13f2a 100644 --- a/src/com/hellogithub/service/articleService.java +++ b/src/com/hellogithub/service/articleService.java @@ -39,6 +39,35 @@ public class articleService { return JSONObject.toJSONString(dataMap1); } + public String ArticleSortBylast(int userid){ + List articleEntityList =articleDao.ArticleSortBylast(); + List articleEntityList1=new ArrayList<>(); + Map dataMap; + Map> dataMap1 = new HashMap<>(); + for(int i=0;i(); + articleEntity articleEntity = articleEntityList.get(i); + int id = articleEntity.getUserId(); + if(id == userid){ + String username = userDao.selectNameById(id); + dataMap.put("ArticleContent",articleEntity.getArticleContent()); + dataMap.put("ArticleId",articleEntity.getArticleId()); + dataMap.put("ArticleTitle",articleEntity.getArticleTitle()); + dataMap.put("IsValid",articleEntity.getIsValid()); + dataMap.put("ReadCount",articleEntity.getReadCount()); + dataMap.put("username",username); + dataMap.put("publishtime",articleEntity.getPublishTime()); + dataMap.put("articleico",articleEntity.getArticleIco()); + dataMap1.put(i+"", dataMap); + articleEntityList1.add(articleEntity); + }else{ + continue; + } + } + return JSONObject.toJSONString(dataMap1); + } + public String ArticleSortByhot(){ List articleEntityList =articleDao.ArticleSortByhot(); diff --git a/src/com/hellogithub/servlet/article/ArticlePublish.java b/src/com/hellogithub/servlet/article/ArticlePublish.java index 312be9c..de3ab34 100644 --- a/src/com/hellogithub/servlet/article/ArticlePublish.java +++ b/src/com/hellogithub/servlet/article/ArticlePublish.java @@ -1,6 +1,7 @@ package com.hellogithub.servlet.article; import com.alibaba.fastjson.JSONObject; +import com.hellogithub.entity.userEntity; import com.hellogithub.service.UserService; import com.hellogithub.service.articleService; import javax.servlet.ServletException; @@ -37,9 +38,9 @@ public class ArticlePublish extends HttpServlet { PrintWriter writer = resp.getWriter(); HttpSession session = req.getSession(); - if(session == null){ + userEntity user = (userEntity)session.getAttribute("user"); + if(user == null){ setResultError("用户未登录", writer); - writer.close(); }else{ String username = req.getParameter("username"); String articlecontent = req.getParameter("articleContent"); @@ -54,6 +55,7 @@ public class ArticlePublish extends HttpServlet { writer.close(); }else{ setResultError("发布失败", writer); + writer.close(); } } } diff --git a/src/com/hellogithub/servlet/userDetailServlet.java b/src/com/hellogithub/servlet/userDetailServlet.java index ac669d0..0101b8d 100644 --- a/src/com/hellogithub/servlet/userDetailServlet.java +++ b/src/com/hellogithub/servlet/userDetailServlet.java @@ -3,6 +3,7 @@ package com.hellogithub.servlet; import com.alibaba.fastjson.JSONObject; import com.hellogithub.entity.userEntity; import com.hellogithub.service.UserService; +import com.hellogithub.service.articleService; import com.hellogithub.service.commentService; import com.hellogithub.service.projectService; import javax.servlet.ServletConfig; @@ -22,6 +23,8 @@ import java.util.Map; public class userDetailServlet extends HttpServlet { private UserService userService=new UserService(); private projectService projectService= new projectService(); + + private articleService articleService= new articleService(); private commentService commentService= new commentService(); @Override public void init(ServletConfig config) throws ServletException { @@ -59,6 +62,7 @@ public class userDetailServlet extends HttpServlet { dataMap.put("comment",commentService.selectByUserId(id)); dataMap.put("project",projectService.retProjectByUserId(id)); dataMap.put("like",projectService.retProBySupport(id)); + dataMap.put("article",articleService.ArticleSortBylast(id)); jsonString = JSONObject.toJSONString(dataMap); writer.println(jsonString); writer.close();