⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commentservice.java

📁 模仿当当网基于struts+hierbernate与mysql的商务网站。
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -