Java項目:BBS技術論壇系統(java+SSM+JSP+bootstrap+Mysql)

qq1334611189 2022-06-23 15:19:36 阅读数:153

javabbsjava+ssm+jsp+bootstrap+mysqljavassm

源碼獲取:俺的博客首頁 "資源" 裏下載!

項目介紹

本項目包含前後臺,前臺為普通用戶登錄,後臺為管理員登錄;

管理員角色包含以下功能:
管理員登錄,删除或者編輯用戶的帖子,後臺管理,友情鏈接管理,用戶管理,版塊管理,網站設置,用戶設置,版塊主題管理等功能。

用戶角色包含以下功能:
用戶首頁,用戶登錄注册,發錶回複,查看帖子,發帖子,個人資料管理,查看我的帖子和回複等功能。


環境需要

1.運行環境:最好是java jdk 1.8,我們在這個平臺上運行的。其他版本理論上也可以。
2.IDE環境:IDEA,Eclipse,Myeclipse都可以。推薦IDEA;
3.tomcat環境:Tomcat 7.x,8.x,9.x版本均可
4.硬件環境:windows 7/8/10 1G內存以上;或者 Mac OS; 
5.數據庫:MySql 5.7版本;
6.是否Maven項目: 否;


技術棧

1. 後端:Spring+SpringMVC+Mybatis
2. 前端:JSP+bootstrap+jQuery


使用說明

1. 使用Navicat或者其它工具,在mysql中創建對應名稱的數據庫,並導入項目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse導入項目,Eclipse/MyEclipse導入時,若為maven項目請選擇maven;
若為maven項目,導入成功後請執行maven clean;maven install命令,然後運行;
3. 將項目中beans.xml配置文件中的數據庫配置改為自己的配置;
4. 運行項目,輸入localhost:8080/ 登錄


 

 

 

 

 

用戶操作頁面: 

/*
* 用戶操作頁面
*
*/
@Controller
@RequestMapping("/user")
public class UserContriller {
@Autowired
UserService userService;
//跳轉個人首頁首頁
@RequestMapping("index.do")
public String index(HttpServletRequest request) {
if(Tool.ismobile(request)){
return "jsp/mobile/user/user";
}else{
return "jsp/index/user/user-ziliao";
}
}
//查看個人資料
@RequestMapping("ziliao.do")
public String ziliao(HttpServletRequest request) {
if(Tool.ismobile(request)){
return "jsp/mobile/user/user-ziliao";
}else{
return "jsp/index/user/user-ziliao";
}
}
//修改用戶
@RequestMapping("update.do")
public String update(HttpServletRequest request, Model model,User user) {
User sessionuser=(User)request.getSession().getAttribute(PublicStatic.USER);
user.setId(sessionuser.getId());
userService.update(user);
user=userService.findbyuserid(sessionuser.getId());
request.getSession().setAttribute(PublicStatic.USER, user);
return "redirect:/user/index.do";
}
//退出
@RequestMapping("logout.do")
public String logout(HttpServletRequest request,HttpServletResponse response) {
HttpSession session = request.getSession();
session.invalidate();
Cookie[] cookies=request.getCookies();
for(Cookie cookie: cookies){
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
}
return "redirect:/";
}
//跳轉修改密碼
@RequestMapping("topwd.do")
public String topwd(HttpServletRequest request) {
return "jsp/index/user/user-pwd";
}
//修改密碼
@ResponseBody
@RequestMapping("pwd.do")
public String pwd(HttpServletRequest request,String pwd ,String newpwd) {
User sessionuser=(User)request.getSession().getAttribute(PublicStatic.USER);
User user=new User();
user.setId(sessionuser.getId());
user.setPwd(pwd);
String login = userService.login(user, request);
if("1".equals(login)){
user.setPwd(Tool.MD5(newpwd));
userService.update(user);
return "1";
}else{
return "0";
}
}
}

後臺用戶管理頁面:

/*
* 後臺用戶管理頁面
*
*/
@Controller
@RequestMapping("/admin/user")
public class AdminUserContriller {
@Autowired
UserService userService;
@Autowired
GroupService groupService;
@Autowired
JifenGroupService jifenGroupService;
//跳轉首頁
@RequestMapping("index.do")
public String add(HttpServletRequest request, Model model,User user,PageBean<User> page) {
page = userService.findpage(user,page);
model.addAttribute("page", page);
model.addAttribute("quser", user);
return "jsp/admin/user/index";
}
//更新
@RequestMapping("update.do")
public String update(HttpServletRequest request, Model model,User user) {
User sessionuser=(User)request.getSession().getAttribute(PublicStatic.USER);
user.setId(sessionuser.getId());
userService.update(user);
return "redirect:/user/index.do";
}
//删除
@ResponseBody
@RequestMapping("del.do")
public String del(HttpServletRequest request, Model model,User user) {
return userService.delete(user.getId());
}
//重置密碼
@ResponseBody
@RequestMapping("updatepwd.do")
public String updatepwd(HttpServletRequest request, Model model,User user) {
String pwd="123456";
user.setPwd(Tool.MD5(pwd));
userService.update(user);
return "1";
}
//重置密碼
@ResponseBody
@RequestMapping("updateflag.do")
public String updateflag(HttpServletRequest request, Model model,User user) {
userService.update(user);
return "1";
}
//設置管理員
@ResponseBody
@RequestMapping("updategroup.do")
public String updategroup(HttpServletRequest request, Model model,User user,int groupid) {
boolean b = groupService.updategroupbyuser(user.getId(), groupid);
if(b){
return "1";
}else{
return "0";
}
}
//删除用戶帖子 留言 回帖 圖片等信息信息
@ResponseBody
@RequestMapping("deluserallinfo.do")
public String deluserallinfo(HttpServletRequest request, Model model,User user) {
boolean b = userService.deluserallinfo(user.getId());
if(b){
return "1";
}else{
return "0";
}
}
@RequestMapping("tooptions.do")
public String tooptions(HttpServletRequest request, Model model,User user){
user = userService.findbyid(user);
model.addAttribute("user", user);
return "jsp/admin/user/option";
}
/**
* 設置用戶vip等級
* @param request
* @param model
* @param user
* @return
*/
@RequestMapping(value="set_vip.do",method=RequestMethod.GET)
public String setVip(Model model,User user){
user = userService.findbyid(user);
model.addAttribute("user", user);
model.addAttribute("jifenGroupList", jifenGroupService.find(null));
return "jsp/admin/user/set_vip";
}
/**
* 設置用戶vip等級錶單提交
* @param userId
* @param jifen
* @return
*/
@RequestMapping(value="set_vip.do",method=RequestMethod.POST)
public String setVip(Integer userId, String vipLevel){
User user = new User();
user.setId(userId);
user = userService.findbyid(user);
user.setVipLevel(vipLevel);
userService.update(user);
return "redirect:index.do";
}
}

上傳圖片控制層: 

/*
* 上傳圖片
*
*/
@Controller
@RequestMapping("/upload")
public class UploadController {
@ResponseBody
@RequestMapping("uploadimg.do")
public Map<String, String> findAllWhere(HttpServletRequest request) throws IOException {
//0代錶失敗,1代錶成功,2格式錯誤
Map<String, String> map=new HashMap<String, String>();
// 轉型為MultipartHttpRequest
try {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<MultipartFile> fileList = multipartRequest.getFiles("file");
for (MultipartFile mf : fileList) {
if(!mf.isEmpty()){
try {
// 文件保存路徑
String dirname=Tool.getyyyyMMdd();
String filePath =PublicStatic.FILE_PATH+"image/"+dirname+"/";
File file = new File(filePath);
if (!file.exists()) {
file.mkdirs();
}
String filenamelast=getfilenamelast(mf.getOriginalFilename()).toUpperCase();
if(!filenamelast.equals(".JPG")&&!filenamelast.equals(".GIF")&&!filenamelast.equals(".JPEG")&&!filenamelast.equals(".PNG")&&!filenamelast.equals(".SWF")){
map.put("isok", "2");
}else{
filenamelast=Tool.getyyyyMMddHHmmssSSS()+Tool.getRandom()+filenamelast;
map.put("isok", "1");
map.put("path", dirname+"/"+filenamelast);
// 轉存文件
mf.transferTo(new File(filePath+filenamelast));
}
} catch (Exception e) {
map.put("isok", "0");
e.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return map;
}
//獲取文件名
private String getfilenamelast(String filename){
int start=filename.lastIndexOf(".");
if(start!=-1){
filename=filename.substring(start, filename.length());
}
return filename;
}
}

源碼獲取:俺的博客首頁 "資源" 裏下載!

版权声明:本文为[qq1334611189]所创,转载请带上原文链接,感谢。 https://gsmany.com/2022/174/202206231438096236.html