栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java项目-宿舍管理系统

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java项目-宿舍管理系统

作者主页:夜未央5788

 简介: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版本;

技术栈

1. 后端:spring+spring mvc+hibernate
2. 前端:easyui+jQuery+JSP

使用说明

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 登录

5. 管理员用户名:admin 密码:admin

运行截图

代码相关 学生管理控制器
@Controller
@RequestMapping("/studentController")
public class StudentController extends BaseController{

	private static final Logger logger = Logger.getLogger(StudentController.class);
	
	@Autowired
	private StudentService studentService;
	
	
	@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;
	
	
	@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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1007242.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号