package com.java1234.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; import com.java1234.model.Comment; import com.java1234.model.PageBean; import com.java1234.util.DateUtil; import com.java1234.util.StringUtil; public class CommentDao { public List<Comment> commentList(Connection con,Comment s_comment,PageBean pageBean,String bCommentDate,String aCommentDate)throws Exception{ List<Comment> commentList=new ArrayList<Comment>(); StringBuffer sb=new StringBuffer("select * from t_comment t1,t_news t2 where t1.newsId=t2.newsId"); if(s_comment.getNewsId()!=-1){ sb.append(" and t1.newsId="+s_comment.getNewsId()); } if(StringUtil.isNotEmpty(bCommentDate)){ sb.append(" and TO_DAYS(t1.commentDate)>=TO_DAYS('"+bCommentDate+"')"); } if(StringUtil.isNotEmpty(aCommentDate)){ sb.append(" and TO_DAYS(t1.commentDate)<=TO_DAYS('"+aCommentDate+"')"); } sb.append(" order by t1.commentDate desc "); if(pageBean!=null){ sb.append(" limit "+pageBean.getStart()+","+pageBean.getPageSize()); } PreparedStatement pstmt=con.prepareStatement(sb.toString()); ResultSet rs=pstmt.executeQuery(); while(rs.next()){ Comment comment=new Comment(); comment.setCommentId(rs.getInt("commentId")); comment.setNewsId(rs.getInt("newsId")); comment.setNewsTitle(rs.getString("title")); comment.setContent(rs.getString("content")); comment.setUserIP(rs.getString("userIP")); comment.setCommentDate(DateUtil.formatString(rs.getString("commentDate"), "yyyy-MM-dd HH:mm:ss")); commentList.add(comment); } return commentList; } public int commentCount(Connection con,Comment s_comment,String bCommentDate,String aCommentDate)throws Exception{ StringBuffer sb=new StringBuffer("select count(*) as total from t_comment"); if(s_comment.getNewsId()!=-1){ sb.append(" and newsId="+s_comment.getNewsId()); } if(StringUtil.isNotEmpty(bCommentDate)){ sb.append(" and TO_DAYS(commentDate)>=TO_DAYS('"+bCommentDate+"')"); } if(StringUtil.isNotEmpty(aCommentDate)){ sb.append(" and TO_DAYS(commentDate)<=TO_DAYS('"+aCommentDate+"')"); } PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where")); ResultSet rs=pstmt.executeQuery(); if(rs.next()){ return rs.getInt("total"); }else{ return 0; } } public int commentAdd(Connection con,Comment comment)throws Exception{ String sql="insert into t_comment values(null,?,?,?,now())"; PreparedStatement pstmt=con.prepareStatement(sql); pstmt.setInt(1, comment.getNewsId()); pstmt.setString(2, comment.getContent()); pstmt.setString(3, comment.getUserIP()); return pstmt.executeUpdate(); } public int commentDelete(Connection con,String commentIds)throws Exception{ String sql="delete from t_comment where commentId in ("+commentIds+")"; PreparedStatement pstmt=con.prepareStatement(sql); return pstmt.executeUpdate(); } }

pangzhihui LV14
2024年3月14日
syczzxj LV10
2023年6月6日
微信网友_5975606834761728 LV3
2023年3月21日
2716804680 LV9
2023年3月10日
Roninljy LV1
2023年2月16日
1721281527 LV2
2022年12月28日
zhang123zz LV1
2022年10月30日
benbosn LV15
2022年8月31日
李海洋 LV12
2022年5月31日
ewan007 LV30
2022年3月11日

陈小灏 LV18
1月4日
qwqwx585160 LV2
2024年12月15日
文巾方
2024年10月30日
暂无贡献等级
asdfgh112
2024年7月4日
暂无贡献等级
微信网友_7041475584184320
2024年6月17日
暂无贡献等级
bankroll LV5
2024年6月13日
玖零定制问题修复 LV34
2024年4月4日
WBelong LV8
2023年12月27日
wttttts LV2
2023年12月24日
black8angel LV4
2023年12月22日