From c955633d887bece594fb7749730d8a686d419719 Mon Sep 17 00:00:00 2001 From: User_cyk <1020691186@qq.com> Date: Wed, 5 Jul 2023 14:44:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/hellogithub/dao/UserDao.java | 3 ++- src/com/hellogithub/dao/commentDao.java | 23 ++++++++++++++++--- .../hellogithub/service/commentService.java | 4 ++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/com/hellogithub/dao/UserDao.java b/src/com/hellogithub/dao/UserDao.java index 04ae06d..aada5a9 100644 --- a/src/com/hellogithub/dao/UserDao.java +++ b/src/com/hellogithub/dao/UserDao.java @@ -211,7 +211,8 @@ public class UserDao { while(rs.next()){ Value = rs.getInt(8); - }return Value; + } + return Value; }catch(Exception e){ e.printStackTrace(); diff --git a/src/com/hellogithub/dao/commentDao.java b/src/com/hellogithub/dao/commentDao.java index 4912905..3da7646 100644 --- a/src/com/hellogithub/dao/commentDao.java +++ b/src/com/hellogithub/dao/commentDao.java @@ -7,6 +7,8 @@ import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.BeanListHandler; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; @@ -56,14 +58,29 @@ public class commentDao { return commentEntityList; } - public List selectByTrait(String id,String trait) + public List selectBylikeNum(String id) { List commentEntityList ; try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql = "select * from comment where projectId = ? and isValid = 1 Order BY ?"; - commentEntityList = runner.query(conn, sql,new BeanListHandler<>(commentEntity.class),id,trait); + String sql = "select * from comment where projectId = ? and isValid = 1 Order BY likeNum DESC"; + commentEntityList = runner.query(conn, sql,new BeanListHandler<>(commentEntity.class),id); + conn.close(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + return commentEntityList; + } + + public List selectByCreatTime(String id) + { + List commentEntityList ; + try { + Connection conn = JdbcUtils.getConnection(); + QueryRunner runner = new QueryRunner(); + String sql = "select * from comment where projectId = ? and isValid = 1 Order BY creatTime "; + commentEntityList = runner.query(conn, sql,new BeanListHandler<>(commentEntity.class),id); conn.close(); } catch (SQLException e) { throw new RuntimeException(e); diff --git a/src/com/hellogithub/service/commentService.java b/src/com/hellogithub/service/commentService.java index 3b62a0a..c28e561 100644 --- a/src/com/hellogithub/service/commentService.java +++ b/src/com/hellogithub/service/commentService.java @@ -59,11 +59,11 @@ public class commentService { List commentEntityList=new ArrayList<>(); if(trait.equals("last")) { - commentEntityList = commentDao.selectByTrait(id,"creatTime"); + commentEntityList = commentDao.selectByCreatTime(id); } if(trait.equals("hot")) { - commentEntityList = commentDao.selectByTrait(id,"likeNum"); + commentEntityList = commentDao.selectBylikeNum(id); } for(int i=0;i