📄 newscommentservice.java
字号:
package com.mycompany.news.service;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import com.mycompany.database.Database;
import com.mycompany.news.dao.NewsCommentDAO;
import com.mycompany.news.dao.impl.NewsCommentDAOImpl;
import com.mycompany.news.dto.News;
import com.mycompany.news.dto.NewsComment;
public class NewsCommentService extends BaseService {
private NewsCommentDAO dao = new NewsCommentDAOImpl();
/**
* 添加评论
* @param comment
* @return
*/
public boolean addComment(NewsComment comment){
Connection conn=null;
try {
conn =Database.getConnection();
dao.setConnection(conn);
dao.addNewsComment(comment);
Database.commit();
setMessage("评论成功,等待审核");
return true;
} catch (Exception e) {
setMessage(e.getMessage());
return false;
}finally{
Database.releaseConnection(conn);
}
}
/**
* 删除评论
* @param comment
* @return
*/
public boolean deleteComment(NewsComment comment){
Connection conn=null;
try {
conn =Database.getConnection();
dao.setConnection(conn);
dao.deleteNewsComment(comment);
Database.commit();
return true;
} catch (Exception e) {
// TODO: handle exception
return false;
}finally{
Database.releaseConnection(conn);
}
}
/**
* 列出分页评论(包括未审核)
* @param news
* @param pageNo
* @param pageSize
* @return
*/
public List listComment(News news,int pageNo,int pageSize){
Connection conn=null;
try {
conn =Database.getConnection();
dao.setConnection(conn);
List ret =dao.getNewsComment(news,pageNo,pageSize);
return ret;
} catch (Exception e) {
// TODO: handle exception
return new ArrayList();
}finally{
Database.releaseConnection(conn);
}
}
/**
* 分页列出已审核的评论
* @param news
* @param pageNo
* @param pageSize
* @return
*/
public List listPublicComment(News news,int pageNo,int pageSize){
Connection conn=null;
try {
conn =Database.getConnection();
dao.setConnection(conn);
List ret =dao.listPublicComment(news,pageNo,pageSize);
return ret;
} catch (Exception e) {
// TODO: handle exception
return new ArrayList();
}finally{
Database.releaseConnection(conn);
}
}
public boolean auditComment(NewsComment comment) {
Connection conn=null;
try {
conn =Database.getConnection();
dao.setConnection(conn);
boolean ret =dao.auditComment(comment);
Database.commit();
return ret;
} catch (Exception e) {
setMessage(e.getMessage());
return false;
}finally{
Database.releaseConnection(conn);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -