Java项目:宿舍管理系统

作者主页:Java毕设网

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

一、项目介绍

宿舍管理系统,主要功能包括:
信息管理:
学生管理、班级管理、访客管理、损耗管理、宿舍管理、宿舍评分;
系统管理:
用户管理、角色管理、菜单管理;

二、环境需要

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.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 
6.数据库:MySql 5.7版本;

三、技术栈

JSP+CSS+JavaScript+servlet+mysql

四、使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 将项目中db-config.properties配置文件中的数据库配置改为自己的配置;

3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;

4. 运行项目,输入http://localhost:8080/xxx 登录

五、运行截图


六、相关代码

学生管理控制器

@Controller
@RequestMapping("/studentController")
public class StudentController extends BaseController{

	private static final Logger logger = Logger.getLogger(StudentController.class);
	
	@Autowired
	private StudentService studentService;
	
	/**
	 * 初始访问
	 * @param 
	 * @param model
	 * @return
	 */
	@RequestMapping(params="goStudent")
    public ModelAndView goStudent(HttpServletRequest request){
        return new ModelAndView("buss/student");
    }
	
	@RequestMapping(params="save")
    @ResponseBody
	public AjaxJson save(HttpServletRequest request, HttpServletResponse response, StudentEntity student, String dormid,String classid) throws Exception {
		AjaxJson j = new AjaxJson();
		j.setMsg("保存成功!");
		j.setSuccess(true);
		try{
			DormEntity de = this.studentService.get(DormEntity.class, dormid);
			ClassEntity ce = this.studentService.get(ClassEntity.class, classid);
			student.setDorm(de);
			student.setClasses(ce);
			int surplus = Integer.parseInt(de.getUsed());
			if(surplus <= 0){
				j.setMsg("该宿舍床位已满");
				j.setSuccess(false);
				return j;
			}
			surplus--;
			de.setUsed(String.valueOf(surplus));
			this.studentService.update(de);
			this.studentService.save(student);
		}catch(Exception e){
			j.setMsg("保存失败!");
			j.setSuccess(false);
		}
		 return j;
		
	}
	
	@RequestMapping(params="update")
    @ResponseBody
	public AjaxJson update(HttpServletRequest request, HttpServletResponse response, StudentEntity student, String dormid,String classid) throws Exception {
		AjaxJson j = new AjaxJson();
		j.setMsg("更新成功!");
		j.setSuccess(true);
		try{
			StudentEntity se = this.studentService.get(StudentEntity.class, student.getId());
			DormEntity de = this.studentService.get(DormEntity.class, dormid);
			DormEntity beforeDorm = this.studentService.get(DormEntity.class, se.getDorm().getId());
			ClassEntity ce = this.studentService.get(ClassEntity.class, classid);
			student.setDorm(de);
			student.setClasses(ce);
			
			if(!de.getId().equals(beforeDorm.getId())){
				int surplus = Integer.parseInt(de.getUsed());
				if(surplus <= 0){
					j.setMsg("该宿舍床位已满");
					j.setSuccess(false);
					return j;
				}
				int beforeSurplus = Integer.parseInt(beforeDorm.getUsed());
				beforeSurplus++;
				surplus--;
				de.setUsed(String.valueOf(surplus));
				beforeDorm.setUsed(String.valueOf(beforeSurplus));
				this.studentService.update(de);
				this.studentService.update(beforeDorm);
			}
			
			this.studentService.update(student);
		}catch(Exception e){
			j.setMsg("更新失败!");
			j.setSuccess(false);
		}
		 return j;
		
	}
	
	@RequestMapping(params="checkOut")
    @ResponseBody
	public AjaxJson checkOut(HttpServletRequest request, HttpServletResponse response, String stuId) throws Exception {
		AjaxJson j = new AjaxJson();
		j.setMsg("退宿成功!");
		j.setSuccess(true);
		try{
			doCheckOut(stuId,true);
		}catch(Exception e){
			j.setMsg("退宿失败!");
			j.setSuccess(false);
		}
		 return j;
		
	}
	
	private void doCheckOut(String stuId,boolean delete){
		StudentEntity student = this.studentService.get(StudentEntity.class, stuId);
		DormEntity de = this.studentService.get(DormEntity.class, "1");
		DormEntity beforeDorm = this.studentService.get(DormEntity.class, student.getDorm().getId());
		student.setDorm(de);
		int surplus = Integer.parseInt(beforeDorm.getUsed());
		surplus++;
		beforeDorm.setUsed(String.valueOf(surplus));
		this.studentService.update(beforeDorm);
		if(!delete){
			this.studentService.update(student);
		}
		
	}
	
	@RequestMapping(params="delete",method=RequestMethod.POST)
    @ResponseBody
	public AjaxJson delete(HttpServletRequest request, HttpServletResponse response, String ids) throws Exception {
		AjaxJson j = new AjaxJson();
		j.setMsg("删除成功!");
		j.setSuccess(true);
		try{
			for(String id:ids.split(",")){
				StudentEntity student = this.studentService.get(StudentEntity.class, id);
				doCheckOut(id,false);
				this.studentService.delete(student);
			}
		}catch(ConstraintViolationException ce){
			ce.printStackTrace();
			j.setMsg("删除失败,存在外键引用,请查看其它数据项中是否有与当前数据有关的信息!");
			j.setSuccess(false);
		}catch(Exception e){
			j.setMsg("删除失败!");
			j.setSuccess(false);
		}
		 return j;
		
	}
	
	@RequestMapping(params="datagrid")
    @ResponseBody
	public void datagrid(HttpServletRequest request, HttpServletResponse response,StudentEntity student,String dormName) throws Exception {
		String page = request.getParameter("page");
		String rows = request.getParameter("rows");
		if(page == null){
			page = "0";
		}
		if(rows == null){
			rows = "0";
		}
		DetachedCriteria condition = DetachedCriteria.forClass(StudentEntity.class);
		Pagination<?> pagination = studentService.findPageData(condition,student,Integer.parseInt(page), Integer.parseInt(rows),dormName);
		JSONObject jobj = new JSONObject();
		jobj.put("total", pagination.getTotalCount());
		jobj.put("rows", pagination.getDatas());

        response.setCharacterEncoding("utf-8");
        response.getWriter().write(jobj.toString());  
		
	}
	
}

访客管理控制器

@Controller
@RequestMapping("/visitorController")
public class VisitorController extends BaseController{

	private static final Logger logger = Logger.getLogger(VisitorController.class);
	
	@Autowired
	private VisitorService visitorService;
	
	/**
	 * 初始访问
	 * @param 
	 * @param model
	 * @return
	 */
	@RequestMapping(params="goVisitor")
    public ModelAndView goVisitor(HttpServletRequest request){
        return new ModelAndView("buss/visitor");
    }
	
	@RequestMapping(params="save")
    @ResponseBody
	public AjaxJson save(HttpServletRequest request, HttpServletResponse response, VisitorEntity visitorEntity,String studentid) throws Exception {
		AjaxJson j = new AjaxJson();
		j.setMsg("保存成功!");
		j.setSuccess(true);
		try{
			StudentEntity se = this.visitorService.get(StudentEntity.class, studentid);
			visitorEntity.setStudent(se);
			this.visitorService.save(visitorEntity);
		}catch(Exception e){
			j.setMsg("保存失败!");
			j.setSuccess(false);
		}
		 return j;
		
	}
	
	@RequestMapping(params="update")
    @ResponseBody
	public AjaxJson update(HttpServletRequest request, HttpServletResponse response, VisitorEntity visitorEntity,String studentid) throws Exception {
		AjaxJson j = new AjaxJson();
		j.setMsg("更新成功!");
		j.setSuccess(true);
		try{
			StudentEntity se = this.visitorService.get(StudentEntity.class, studentid);
			visitorEntity.setStudent(se);
			this.visitorService.update(visitorEntity);
		}catch(Exception e){
			j.setMsg("更新失败!");
			j.setSuccess(false);
		}
		 return j;
		
	}
	
	@RequestMapping(params="delete",method=RequestMethod.POST)
    @ResponseBody
	public AjaxJson delete(HttpServletRequest request, HttpServletResponse response, String ids) throws Exception {
		AjaxJson j = new AjaxJson();
		j.setMsg("删除成功!");
		j.setSuccess(true);
		try{
			for(String id:ids.split(",")){
				VisitorEntity visitorEntity = new VisitorEntity();
				visitorEntity.setId(id);
				this.visitorService.delete(visitorEntity);
			}
		}catch(Exception e){
			j.setMsg("删除失败!");
			j.setSuccess(false);
		}
		 return j;
		
	}
	
	@RequestMapping(params="datagrid")
    @ResponseBody
	public void datagrid(HttpServletRequest request, HttpServletResponse response, VisitorEntity ve,String studentname) throws Exception {
		String page = request.getParameter("page");//easyui datagrid 分页 页号
		String rows = request.getParameter("rows");//easyui datagrid 分页 页数
		if(page == null){
			page = "0";
		}
		if(rows == null){
			rows = "0";
		}
		DetachedCriteria condition = DetachedCriteria.forClass(VisitorEntity.class);
		Pagination<?> pagination = visitorService.findPageData(condition,ve,Integer.parseInt(page), Integer.parseInt(rows),studentname);
		
		JSONObject jobj = new JSONObject();
		jobj.put("total", pagination.getTotalCount());
		jobj.put("rows", pagination.getDatas());

        response.setCharacterEncoding("utf-8");  
        response.getWriter().write(jobj.toString());
		
	}
	
}

七、如果也想学习本系统,下面领取。关注并回复:003ssh

  • 7
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值