Java项目:BBS技术论坛系统(java+SSM+JSP+bootstrap+Mysql)

源码获取:俺的博客首页 "资源" 里下载!

项目介绍

本项目包含前后台,前台为普通用户登录,后台为管理员登录;

管理员角色包含以下功能:
管理员登录,删除或者编辑用户的帖子,后台管理,友情链接管理,用户管理,版块管理,网站设置,用户设置,版块主题管理等功能。

用户角色包含以下功能:
用户首页,用户登录注册,发表回复,查看帖子,发帖子,个人资料管理,查看我的帖子和回复等功能。


环境需要

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;
    }
    
}

源码获取:俺的博客首页 "资源" 里下载!

猜你喜欢

转载自blog.csdn.net/yuyecsdn/article/details/125423800
今日推荐