commentservice.java
来自「模仿当当网基于struts+hierbernate与mysql的商务网站。」· Java 代码 · 共 46 行
JAVA
46 行
package org.whatisjava.dang.service;
import java.util.List;
import org.whatisjava.dang.dao.CommentDao;
import org.whatisjava.dang.dao.CommentReplyDao;
import org.whatisjava.dang.domain.Comment;
import org.whatisjava.dang.domain.CommentReply;
import org.whatisjava.dang.domain.Product;
import org.whatisjava.dang.domain.User;
public class CommentService {
private CommentDao commentDao=new CommentDao();
private CommentReplyDao replyDao=new CommentReplyDao();
public void createComment(Comment comment) {
commentDao.save(comment);
}
public Comment getCommentById(Integer id, boolean withReply) {
return commentDao.getById(id,withReply);
}
public Comment getCommentById(Integer id) {
return this.getCommentById(id, false);
}
public void createReply(CommentReply reply) {
Comment comment=this.getCommentById(reply.getCommentId(), true);
comment.getReplies().add(reply);
commentDao.update(comment );
}
public List<Comment> findCommentByUser(User user, boolean withReply) {
return commentDao.findByUser(user,withReply);
}
public List<CommentReply> findReplyByUser(User user) {
return replyDao.findByUser(user);
}
public List<Comment> findCommentByProduct(Product product, boolean withReply) {
return commentDao.findByProduct(product,withReply);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?