Java项目-SSM实现完整的BBS论坛
Posted 编程指南针
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java项目-SSM实现完整的BBS论坛相关的知识,希望对你有一定的参考价值。
项目编号:BS-PT-002
这个论坛功能开发的比较完整,论坛的版块管理,贴子管理,发贴,回复,置顶,个人积分等功能都具备。系统采用SSM框架技术开发,数据库采用mysql,开发工具采用IDEA或MyEclipse均可。
前端用户交流功能
登录后进入个人管理模块
进入相应版块发贴交流
如果用户具备管理员权限,可以编辑和删除贴子,也可置顶,取消置顶,设置精华等操作
如果是管理员角色可以进入后台进行管理操作,主要包括友情链接添加,板块管理,用户管理,内部连接管理,网站设置等功能
部分核心实现代码:
package cc.javaee.bbs.controller.admin;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cc.javaee.bbs.model.Bankuai;
import cc.javaee.bbs.model.JifenGroup;
import cc.javaee.bbs.model.PageBean;
import cc.javaee.bbs.model.User;
import cc.javaee.bbs.service.BankuaiService;
import cc.javaee.bbs.service.JifenGroupService;
import cc.javaee.bbs.tool.Pinyin4j;
import cc.javaee.bbs.tool.PublicStatic;
import cc.javaee.bbs.tool.Tool;
import cc.javaee.bbs.tool.thread.IndexThread;
/*
* 后台板块查询
*
*/
@Controller
@RequestMapping("/admin/bankuai")
public class AdminBankuaiController
@Autowired
BankuaiService bankuaiService;
@Autowired
JifenGroupService jifenGroupService;
private static Logger log = Logger.getLogger(AdminBankuaiController.class);
//后台页面查询
@RequestMapping("index.do")
public String findAllWhere(HttpServletRequest request, Model model,Bankuai bankuai,PageBean<Bankuai> page)
Bankuai bankuaitmp=new Bankuai();
bankuaitmp.setParentId(0);
List<Bankuai> list = bankuaiService.select(bankuaitmp);
page = bankuaiService.findpage(bankuai,page);
model.addAttribute("list", list);
model.addAttribute("bankuai", bankuai);
model.addAttribute("page", page);
return "jsp/admin/bankuai/index";
//跳转到修改页面
@RequestMapping("toupdateoradd.do")
public String toupdateoradd(Bankuai bankuai, Model model)
if(bankuai.getId()!=null)
bankuai=bankuaiService.findbyid(bankuai);
model.addAttribute("bankuai", bankuai);
List<Bankuai> parentList = bankuaiService.findbyparentId(new Bankuai());
//如果是父板块,删除自己
for (int i=0;i< parentList.size() ;i++)
Bankuai bankuai2=parentList.get(i);
if(bankuai2.getId()==bankuai.getId())
parentList.remove(bankuai2);
model.addAttribute("parentList", parentList);
List<JifenGroup> jifengouplist = jifenGroupService.find(new JifenGroup());
model.addAttribute("jifengouplist", jifengouplist);
return "jsp/admin/bankuai/updateoradd";
//修改或者新增
@RequestMapping("updateoradd.do")
public String updateoradd(HttpServletRequest request,Bankuai bankuai)
User user=(User)request.getSession().getAttribute(PublicStatic.USER);
bankuai.setCreateUserid(user.getId());
String img = bankuai.getImg();
if(img!=null&&img.length()==0)
bankuai.setImg("bankuai.jpg");
if(bankuai.getId()!=null)
bankuaiService.update(bankuai);
else
bankuaiService.insert(bankuai);
new IndexThread().start();
return "redirect:index.do ";
//删除
@ResponseBody
@RequestMapping("del.do")
public String del(int id)
String result=bankuaiService.delete(id);
return result;
//删除
@ResponseBody
@RequestMapping("getpinyin.do")
public String getpinyin(String name)
String getpinyin = Pinyin4j.getpinyin(name);
Bankuai bankuai=new Bankuai();
bankuai.setYuming(getpinyin);
List<Bankuai> list = bankuaiService.select(bankuai);
if(list.size()>0)
getpinyin=getpinyin+Tool.getRandom();
return getpinyin;
package cc.javaee.bbs.controller.admin;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cc.javaee.bbs.model.Tiezi;
import cc.javaee.bbs.model.User;
import cc.javaee.bbs.service.TieziService;
import cc.javaee.bbs.tool.PublicStatic;
import cc.javaee.bbs.tool.Tool;
/*
* 后台公共使用
*
*/
@Controller
@RequestMapping("/admin/common")
public class AdminCommonController
@Autowired
TieziService tieziService;
private static Logger log = Logger.getLogger(AdminCommonController.class);
//全局置顶
@ResponseBody
@RequestMapping("updateallzhiding.do")
public Map<String, String> updateallzhiding(HttpServletRequest request,int id)
Map<String, String> map=new HashMap<String, String>();
Tiezi tiezi=new Tiezi();
tiezi.setId(id);
tiezi.setZhiding(PublicStatic.ALLZHIDING);
User user=(User) request.getSession().getAttribute(PublicStatic.USER);
tiezi.setLastupdate(""+user.getGroupname()+"\\""+user.getLoginname()+"\\"于"+Tool.getyyyyMMddHHmmss()+"将帖子全局置顶"+"</br>");
tieziService.update(tiezi);
map.put("flag", "1");
return map;
//取消全局置顶
@ResponseBody
@RequestMapping("updateallqxzhiding.do")
public Map<String, String> updateallqxzhiding(HttpServletRequest request,int id)
Map<String, String> map=new HashMap<String, String>();
Tiezi tiezi=new Tiezi();
tiezi.setId(id);
tiezi.setZhiding("");
User user=(User) request.getSession().getAttribute(PublicStatic.USER);
tiezi.setLastupdate(""+user.getGroupname()+"\\""+user.getLoginname()+"\\"于"+Tool.getyyyyMMddHHmmss()+"将帖子取消全局置顶"+"</br>");
tieziService.update(tiezi);
map.put("flag", "1");
return map;
package cc.javaee.bbs.controller.admin;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/*
*
* 跳转后台首页
*
*/
@Controller
@RequestMapping("/admin")
public class AdminIndexController
private static Logger log = Logger.getLogger(AdminIndexController.class);
//后台页面查询
@RequestMapping("index.do")
public String findAllWhere(HttpServletRequest request, Model model)
return "jsp/admin/index";
package cc.javaee.bbs.controller.admin;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import cc.javaee.bbs.model.Info;
import cc.javaee.bbs.service.InfoService;
/*
* 网站信息
*
*/
@Controller
@RequestMapping("/admin/info")
public class AdminInfoController
@Autowired
InfoService infoService;
private static Logger log = Logger.getLogger(AdminInfoController.class);
//页面查询
@RequestMapping("index.do")
public String findAllWhere(HttpServletRequest request, Model model)
Info info = infoService.find();
model.addAttribute("info", info);
return "jsp/admin/info";
//修改
@RequestMapping("update.do")
public String updateoradd(HttpServletRequest request,Info info)
info.setId(1);
infoService.update(info);
info = infoService.find();
request.getSession().getServletContext().setAttribute("bbsinfo", info);
return "redirect:/admin/info/index.do ";
package cc.javaee.bbs.controller.admin;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cc.javaee.bbs.model.Bankuai;
import cc.javaee.bbs.model.InnerLink;
import cc.javaee.bbs.model.JifenGroup;
import cc.javaee.bbs.model.PageBean;
import cc.javaee.bbs.model.User;
import cc.javaee.bbs.service.BankuaiService;
import cc.javaee.bbs.service.InnerLinkService;
import cc.javaee.bbs.service.JifenGroupService;
import cc.javaee.bbs.tool.Pinyin4j;
import cc.javaee.bbs.tool.PublicStatic;
import cc.javaee.bbs.tool.Tool;
import cc.javaee.bbs.tool.thread.IndexThread;
/*
* 后台内部链接
*
*/
@Controller
@RequestMapping("/admin/innerlink")
public class AdminInnerLinkController
@Autowired
BankuaiService bankuaiService;
@Autowired
JifenGroupService jifenGroupService;
@Autowired
InnerLinkService innerLinkService;
private static Logger log = Logger.getLogger(AdminInnerLinkController.class);
//后台页面查询
@RequestMapping("index.do")
public String findAllWhere(HttpServletRequest request, Model model,InnerLink innerLink,PageBean<InnerLink> page)
page = innerLinkService.findpage(innerLink,page);
model.addAttribute("page", page);
return "jsp/admin/innerlink/index";
//跳转到修改页面
@RequestMapping("toupdateoradd.do")
public String toupdateoradd(Integer id, Model model)
if(id!=null)
InnerLink innerLink=innerLinkService.findbyid(id);
model.addAttribute("innerLink", innerLink);
return "jsp/admin/innerlink/updateoradd";
//修改或者新增
@RequestMapping("updateoradd.do")
public String updateoradd(HttpServletRequest request,InnerLink innerLink)
User user=(User)request.getSession().getAttribute(PublicStatic.USER);
innerLink.setCreateuserid(user.getId());
innerLink.setIsuse("0");
innerLink.setType("0");
innerLink.setCreatetime(Tool.getyyyyMMddHHmmss());
String innerlinkhtml = innerLink.getInnerlink();
if(innerlinkhtml!=null&&innerlinkhtml.length()>0)
if(!innerlinkhtml.startsWith("http://")||!innerlinkhtml.startsWith("http://"))
innerlinkhtml="http://"+innerlinkhtml;
innerLink.setInnerlink(innerlinkhtml);
if(innerLink.getId()!=null)
innerLinkService.update(innerLink);
else
innerLinkService.insert(innerLink);
return "redirect:index.do ";
//删除
@ResponseBody
@RequestMapping("del.do")
public String del(int id)
String result=innerLinkService.delete(id);
return result;
//删除
@ResponseBody
@RequestMapping("updateuse.do")
public String updateuse(int id,String use)
InnerLink innerLink=new InnerLink();
innerLink.setId(id);
innerLink.setIsuse(use);
innerLink.setCreatetime(Tool.getyyyyMMddHHmmss());
innerLinkService.update(innerLink);
new IndexThread().start();
return "1";
package cc.javaee.bbs.controller.admin;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cc.javaee.bbs.model.Bankuai;
import cc.javaee.bbs.model.Link;
import cc.javaee.bbs.model.PageBean;
import cc.javaee.bbs.model.User;
import cc.javaee.bbs.service.BankuaiService;
import cc.javaee.bbs.service.LinkService;
import cc.javaee.bbs.tool.PublicStatic;
/*
* 友情链接
*
*/
@Controller
@RequestMapping("/admin/link")
public class AdminLinkController
@Autowired
LinkService linkService;
@Autowired
BankuaiService bankuaiService;
private static Logger log = Logger.getLogger(AdminLinkController.class);
//后台页面查询
@RequestMapping("index.do")
public String findAllWhere(HttpServletRequest request, Model model,Link link,PageBean<Link> page)
User user=(User) request.getSession().getAttribute(PublicStatic.USER);
link.setCreateuserid(user.getId());
page = linkService.findpage(link,page);
model.addAttribute("page", page);
return "jsp/admin/link/index";
//跳转到修改页面
@RequestMapping("toupdateoradd.do")
public String toupdateoradd(Model model,Link link)
Bankuai bankuai=new Bankuai();
// bankuai.setParentId(0);
List<Bankuai> list = bankuaiService.select(bankuai);
model.addAttribute("list", list);
if(link!=null&&link.getId()!=null)
link=linkService.find(link).get(0);
model.addAttribute("link", link);
return "jsp/admin/link/updateoradd";
//修改或者新增
@RequestMapping("updateoradd.do")
public String updateoradd(HttpServletRequest request,Link link)
User user=(User) request.getSession().getAttribute(PublicStatic.USER);
link.setCreateuserid(user.getId());
if(link.getId()!=null)
linkService.update(link);
else
linkService.insert(link);
return "redirect:index.do ";
//删除
@ResponseBody
@RequestMapping("del.do")
public String del(int id)
String result=linkService.delete(id);
return result;
package cc.javaee.bbs.controller.admin;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cc.javaee.bbs.model.PageBean;
import cc.javaee.bbs.model.Tiezi;
import cc.javaee.bbs.model.User;
import cc.javaee.bbs.service.GroupService;
import cc.javaee.bbs.service.HuifuService;
import cc.javaee.bbs.service.TieziService;
import cc.javaee.bbs.service.UserService;
import cc.javaee.bbs.tool.PublicStatic;
import cc.javaee.bbs.tool.Tool;
/*
* 后台用户管理页面
*
*/
@Controller
@RequestMapping("/admin/post")
public class AdminPostContriller
@Autowired
UserService userService;
@Autowired
GroupService groupService;
@Autowired
TieziService tieziService;
@Autowired
HuifuService huifuService;
//跳转首页
@RequestMapping("index.do")
public String add(HttpServletRequest request, Model model,Tiezi tiezi,PageBean<Tiezi> page)
if("1".equals(tiezi.getIsuse()))
tiezi.setOrderby("5");
else
tiezi.setOrderby("4");
page = tieziService.findpagebybankuanid(tiezi, page);
model.addAttribute("page", page);
model.addAttribute("qtiezi", tiezi);
return "jsp/admin/post/index";
//审核通过
@RequestMapping("updatepost.do")
public String updatepost(HttpServletRequest request, Model model,Tiezi tiezi)
tieziService.updatepost(tiezi);
return "redirect:index.do?isuse=0";
//删除帖子
@RequestMapping("delpost.do")
public String delpost(HttpServletRequest request, Model model,int id)
tieziService.delete(id);
huifuService.deletebytiezi(id);
return "redirect:index.do?isuse=1";
以上是关于Java项目-SSM实现完整的BBS论坛的主要内容,如果未能解决你的问题,请参考以下文章
Java项目:清新论坛系统(java+SSM+mysql+maven+tomcat)
java ssm 后台框架平台 项目源码 websocket 即时通讯 IM quartz spri
基于SSM+JSP实现的兼职论坛网站(用户/管理员登录论坛交流兼职发布用户管理帖子管理兼职管理广告管理信箱管理用户收藏系统公告)