servlet+Mysql实现的校园论坛管理系统(功能包含登录,首页帖子查看、发帖、个人帖子删除编辑、帖子评论回复、用户管理等)

servlet+Mysql实现的校园论坛管理系统

本系统是一个简单的校园论坛系统,学生可以在线发帖并进行帖子评论回复,同同时管理员可以对用户进行管理。
(文末查看完整源码)

实现功能截图

登录
请添加图片描述
发帖
请添加图片描述
个人帖子编辑删除
请添加图片描述
个人信息
请添加图片描述
帖子评论回复
请添加图片描述

用户管理
请添加图片描述

系统功能

本系统实现了以下功能:
1、登录
2、发帖
3、帖子查看
4、帖子删除编辑
5、帖子评论回复
6、用户管理

使用技术

数据库:mysql
开发工具:Idea(Myeclispe、Eclipse也可以)
知识点:servlet+jsp

项目结构
在这里插入图片描述

代码

java端
实体类
ForumEntity.java

package com.xh.bbs.entity;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * 帖子实体类
 */
public class ForumEntity {

	private int fid;
	private String title;
	private String content;
//	private Timestamp createTime;
	private Timestamp createTime;
	//关联用户,多对一额关联
	private UserEntity author = new UserEntity();
	//关联回复
	private List<ReplyEntity> replyList = new ArrayList<ReplyEntity>();

	public int getFid() {
		return fid;
	}

	public void setFid(int fid) {
		this.fid = fid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	
	
//	public Timestamp getCreateTime() {
//		return createTime;
//	}
//
//	public void setCreateTime(Timestamp createTime) {
//		this.createTime = createTime;
//	}

	public Timestamp getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}

	public UserEntity getAuthor() {
		return author;
	}

	public void setAuthor(UserEntity author) {
		this.author = author;
	}

	
	
	public List<ReplyEntity> getReplyList() {
		return replyList;
	}

	public void setReplyList(List<ReplyEntity> replyList) {
		this.replyList = replyList;
	}


}

service层
BbsServiceImpl.java

package com.xh.bbs.service;

import java.util.ArrayList;
import java.util.List;

import com.xh.bbs.dao.BbsDaoImpl;
import com.xh.bbs.dao.BbsDaoInf;
import com.xh.bbs.dao.UserDaoImpl;
import com.xh.bbs.dao.UserDaoInf;
import com.xh.bbs.entity.ForumEntity;
import com.xh.bbs.entity.ReplyEntity;
import com.xh.bbs.entity.UserEntity;

public class BbsServiceImpl implements BbsServiceInf{

	
	public List<ForumEntity> findForumList() {
		System.out.println("查询帖子列表");
		BbsDaoInf bbsDao = new BbsDaoImpl();
		UserDaoInf userDao = new UserDaoImpl(); 
	
		List<ForumEntity> forumList = bbsDao.findForumList();
	
		for (ForumEntity forumEntity : forumList) {
			int uid = forumEntity.getAuthor().getUser_id();
			UserEntity author = userDao.findUserById(uid);
			forumEntity.setAuthor(author);
			
			
		}
		System.out.println(forumList);
		return forumList;
	}

	//发表帖子
	public int createForum(ForumEntity forum) {
		BbsDaoInf bbsDao = new BbsDaoImpl();
		return bbsDao.addForum(forum);
	}


	public ForumEntity findReplyList(int fid) {
		BbsDaoInf bbsDao = new BbsDaoImpl();
		UserDaoInf userDao = new UserDaoImpl();
	
		ForumEntity forum = bbsDao.findForumById(fid);		
		UserEntity author = userDao.findUserById(forum.getAuthor().getUser_id());
			
		List<ReplyEntity> replyList = bbsDao.findReplyList(fid);
			
		for (ReplyEntity replyEntity : replyList) {
			UserEntity replyUser = userDao.findUserById(replyEntity.getUser().getUser_id());
			replyEntity.setUser(replyUser);
		}
		
		forum.setAuthor(author);
		forum.setReplyList(replyList);
		return forum;
	}

	//发表回复
	public int createReply(ReplyEntity reply) {
		BbsDaoInf dao = new BbsDaoImpl();
		return dao.addReply(reply);
	}
	
	//查询个人发帖
	public List<ForumEntity> personForum(int pid){
		BbsDaoInf dao=new BbsDaoImpl();
		List<ForumEntity> personList=new ArrayList<ForumEntity>();
		
		personList=dao.personForum(pid);
		
		return (personList==null)?null:personList;
	}
	
	//删除个人帖子
	public void deleteForumByFid(int fid){
		BbsDaoInf dao=new BbsDaoImpl();
		dao.deleteForum(fid);
	}
								
	//删除帖子的所有回复
	public void deleteReplyByFid(int fid){
		BbsDaoInf dao=new BbsDaoImpl();
		dao.deleteReply(fid);
	}
	
	//删除帖子下的某个用户的回帖
	public void deleteReplyByRid(int rid){
		BbsDaoInf dao=new BbsDaoImpl();
		dao.deleteReplyByRid(rid);
	}
			                      //管理员模块
	//删除用户(删除用户信息,发帖信息,回帖信息)
	public void dUserAllForumByUid(int uid){
		BbsDaoInf dao=new BbsDaoImpl();
		dao.dUserAllforumByUid(uid);
	}
	
	//删除该用户所有回帖
	public void dUserAllreplyByUid(int uid){
		BbsDaoInf dao=new BbsDaoImpl();
		dao.dUserAllreplyByUid(uid);
	}
	
	//删除用户帖子下的所有回帖
	public void dUserOtherRelyByFid(int uid){
		BbsDaoInf dao=new BbsDaoImpl();
		dao.dUserOtherRelyByFid(uid);
	}
	
	//查看单个用户发帖情况
	public List<ForumEntity> seeUserForumList(int uid){
		BbsDaoInf dao=new BbsDaoImpl();
		List<ForumEntity> forum=dao.personForum(uid);	
		return forum;
	}
}

servlet层
ForumListServlet.java

package com.xh.bbs.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xh.bbs.entity.ForumEntity;
import com.xh.bbs.service.BbsServiceImpl;
import com.xh.bbs.service.BbsServiceInf;

@SuppressWarnings("serial")
public class ForumListServlet extends HttpServlet{

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		BbsServiceInf service = new BbsServiceImpl();
		List<ForumEntity> forumList = service.findForumList();

		request.setAttribute("forumList", forumList);	
		request.getRequestDispatcher("forumlist.jsp").forward(request, response);
	}
}

FindUserByIdServlet.java

package com.xh.bbs.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xh.bbs.entity.UserEntity;
import com.xh.bbs.service.UserServiceImpl;
import com.xh.bbs.service.UserServiceInf;
@SuppressWarnings("serial")
public class FindUserByIdServlet extends HttpServlet {
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String u_id=request.getParameter("uid");
		int uid=Integer.parseInt(u_id);
		
		UserServiceInf service=new UserServiceImpl();
		UserEntity user=service.findUser(uid);
		request.setAttribute("user",user);
		
		request.getRequestDispatcher("userinfo.jsp").forward(request, response);
		
		
	}

}

完整源码

觉得有用,记得一键三连哦!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

anmu4200

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值