作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目包含管理员、宿舍管理员、学生三种角色;
管理员角色包含以下功能:
管理员登录,院系管理,专业管理,年级管理,班级管理,学生设置,宿舍管理员管理,宿舍楼管理,宿舍管理,床位管理,学生入住登记,学生退房管理等功能。
宿舍管理员角色包含以下功能:
宿舍管理员管理,宿舍楼管理,宿舍管理,床位管理,入住登记,退房管理,个人信息修改等功能。
学生角色包含以下功能:
学生角色登录,我入住的床位,个人信息修改等功能。
环境需要
1.运行环境:java jdk 1.7,注:该项目仅支持jdk1.7,不支持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+CSS+JavaScript+bootstrap+jquery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中config/jdbc.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入http://localhost:8080/ 登录
## 注意事项
该项目仅支持jdk1.7,不支持1.8及以上版本;
运行截图
相关代码
Controller基类
package com.my.xymh.base;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.my.xymh.utils.HttpConstants;
import com.my.xymh.utils.JsonDateValueProcessor;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Set;
/**
* Controller基类
*/
public class BaseController {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
protected final static String DATE_FORMATE = "yyyy-MM-dd";
/**
* 返回服务端处理结果
*
* @param obj
* 服务端输出对象
* @return 输出处理结果给前段JSON格式数据
*/
public String responseResult(Object obj) {
JSONObject jsonObj = null;
if (obj != null) {
logger.info("后端返回对象:{}", obj);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
jsonObj = JSONObject.fromObject(obj, jsonConfig);
logger.info("后端返回数据:" + jsonObj);
}
logger.info("输出结果:{}", jsonObj.toString());
return jsonObj.toString();
}
/**
* 返回成功
*
* @param obj
* 输出对象
* @return 输出成功的JSON格式数据
*/
public String responseSuccess(Object obj) {
JSONObject jsonObj = null;
if (obj != null) {
logger.info("后端返回对象:{}", obj);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
jsonObj = JSONObject.fromObject(obj, jsonConfig);
}
logger.info("输出结果:{}", jsonObj.toString());
return jsonObj.toString();
}
/**
* 返回成功
*
* @param obj
* 输出对象
* @return 输出成功的JSON格式数据
*/
public String responseArraySuccess(Object obj) {
JSONArray jsonObj = null;
if (obj != null) {
logger.info("后端返回对象:{}", obj);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
jsonObj = JSONArray.fromObject(obj, jsonConfig);
logger.info("后端返回数据:" + jsonObj);
}
logger.info("输出结果:{}", jsonObj.toString());
return jsonObj.toString();
}
/**
* 返回成功
*
* @param obj
* 输出对象
* @return 输出成功的JSON格式数据
*/
public String responseSuccess(Object obj, String msg) {
JSONObject jsonObj = null;
JSONObject jsonObj2 = null;
if (obj != null) {
logger.info("后端返回对象:{}", obj);
JsonConfig jsonConfig = new JsonConfig();
//jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
jsonObj = JSONObject.fromObject(obj);
jsonObj2 = new JSONObject();
jsonObj2.put("datas", jsonObj);
jsonObj2.put("message", msg);
logger.info("后端返回数据:" + jsonObj2);
}
logger.info("输出结果:{}", jsonObj2.toString());
return jsonObj2.toString();
}
/**
* 返回失败
*
* @param errorMsg
* 错误信息
* @return 输出失败的JSON格式数据
*/
public String responseFail(String errorMsg) {
JSONObject jsonObj = new JSONObject();
jsonObj.put(HttpConstants.RESPONSE_RESULT_FLAG_ISERROR, true);
jsonObj.put(HttpConstants.SERVICE_RESPONSE_RESULT_MSG, errorMsg);
logger.info("输出结果:{}", jsonObj.toString());
return jsonObj.toString();
}
// 下面是判断null的操作
public boolean isEmpty(String str) {
return (null == str) || (str.trim().length() <= 0);
}
public boolean isEmpty(Character cha) {
return (null == cha) || cha.equals(' ');
}
public boolean isEmpty(Object obj) {
return (null == obj);
}
public boolean isEmpty(Object[] objs) {
return (null == objs) || (objs.length <= 0);
}
public boolean isEmpty(Collection<?> obj) {
return (null == obj) || obj.isEmpty();
}
public boolean isEmpty(Set<?> set) {
return (null == set) || set.isEmpty();
}
public boolean isEmpty(Serializable obj) {
return null == obj;
}
public boolean isEmpty(Map<?, ?> map) {
return (null == map) || map.isEmpty();
}
}
CollegeController
package com.my.xymh.controller;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
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.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import com.my.xymh.base.BaseController;
import com.my.xymh.entity.College;
import com.my.xymh.service.CollegeService;
import com.my.xymh.utils.JsonUtil2;
import com.my.xymh.utils.Pager;
/**
* @ClassName:
* @Description:
* @author administrator
* @date - 2017年02月18日 12时25分56秒
*/
@Controller
@RequestMapping("/college")
public class CollegeController extends BaseController {
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private CollegeService collegeService;
// --------------------------------------- 华丽分割线 ------------------------------
/**
* 分页查询 返回list对象(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObj.do")
public String findByObj(College college, Model model, HttpServletRequest request, HttpServletResponse response) {
List<College> list = collegeService.listAllByEntity(college);
model.addAttribute("list", list);
//分页查询
/*Pager<College> pagers = collegeService.findByEntity(college);
model.addAttribute("pagers", pagers);*/
//存储查询条件
model.addAttribute("obj", college);
return "college/college";
}
/**
* 分页查询 返回list对象(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap.do")
public String findByMap(College college, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(college.getName())){
params.put("content", college.getName());
}
/*if(!isEmpty(college.getAddUserId())){
params.put("addUserId", college.getAddUserId());
}*/
//分页查询
Pager<College> pagers = collegeService.findByMap(params);
model.addAttribute("pagers", pagers);
//存储查询条件
model.addAttribute("obj", college);
return "college/college";
}
/**
* 跳至添加页面
* @return
*/
@RequestMapping(value = "/add.do")
public String add() {
return "college/add";
}
/**
* 添加执行
* @return
*/
@RequestMapping(value = "/exAdd.do")
public String manageMain(College college,Integer id,HttpServletRequest request){
String uuid = UUID.randomUUID().toString().replaceAll("-", "");//生成唯一主键
college.setId(uuid);
collegeService.insert(college);
return "redirect:/college/findByObj.do";
}
/**
* 跳至修改页面
* @return
*/
@RequestMapping(value = "/update.do")
public String update(String id,Model model) {
College obj = collegeService.load(id);
model.addAttribute("obj",obj);
return "college/update";
}
/**
* 添加修改
* @return
*/
@RequestMapping(value = "/exUpdate.do")
public String exUpdate(College college, Model model, HttpServletRequest request, HttpServletResponse response) {
collegeService.update(college);
return "redirect:/college/findByObj.do";
}
/**
* 删除通过主键
* @return
*/
@RequestMapping(value = "/delete.do")
public String delete(String id, Model model, HttpServletRequest request, HttpServletResponse response) {
//真正删除
collegeService.deleteById(id);
return "redirect:/college/findByObj.do";
}
// --------------------------------------- 华丽分割线 ------------------------------
/**
* 分页查询 返回list json(通过对象)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByObj.json", method = RequestMethod.GET)
@ResponseBody
public String findByObjByEntity(College college, Model model, HttpServletRequest request, HttpServletResponse response) {
//分页查询
Pager<College> pagers = collegeService.findByEntity(college);
JSONObject jsonObject = JsonUtil2.getJsonObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", college);
return jsonObject.toString();
}
/**
* 分页查询 返回list json(通过Map)
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/findByMap.json", method = RequestMethod.GET)
@ResponseBody
public String findByMapMap(College college, Model model, HttpServletRequest request, HttpServletResponse response) {
//通过map查询
Map<String,Object> params = new HashMap<String,Object>();
if(!isEmpty(college.getName())){
params.put("content", college.getName());
}
//分页查询
Pager<College> pagers = collegeService.findByMap(params);
JSONObject jsonObject = JsonUtil2.getJsonObject();
jsonObject.put("pagers", pagers);
jsonObject.put("obj", college);
return jsonObject.toString();
}
/**
* ajax 添加
* @param
* @return
*/
@RequestMapping(value = "/exAdd.json", method = RequestMethod.POST)
@ResponseBody
public String exAddJson(College college, Model model, HttpServletRequest request, HttpServletResponse response) {
collegeService.insert(college);
JSONObject jsonObject = JsonUtil2.getJsonObject();
jsonObject.put("message", "添加成功");
return jsonObject.toString();
}
/**
* ajax 修改
* @param
* @return
*/
@RequestMapping(value = "/exUpdate.json",method = RequestMethod.POST)
@ResponseBody
public String exUpdateJson(College college, Model model, HttpServletRequest request, HttpServletResponse response) {
collegeService.update(college);
JSONObject jsonObject = JsonUtil2.getJsonObject();
jsonObject.put("message", "修改成功");
return jsonObject.toString();
}
/**
* ajax 删除
* @return
*/
@RequestMapping(value = "/delete.json", produces = "text/html;charset=UTF-8", method = RequestMethod.GET)
@ResponseBody
public String exDeleteJson(Integer id, Model model, HttpServletRequest request, HttpServletResponse response) {
//真正删除
collegeService.deleteById(id);
//通过参数删除
//Map<String,Object> params = new HashMap<String,Object>();
//params.put("id", id);
//collegeService.deleteBySqId("deleteBySql", params);
//状态删除
//College load = collegeService.load(id);
//load.setIsDelete(1);
//collegeService.update(load);
JSONObject jsonObject = JsonUtil2.getJsonObject();
jsonObject.put("message", "删除成功");
return jsonObject.toString();
}
/**
* 单文件上传
* @param file
* @param request
* @param model
* @return
*/
@RequestMapping(value = "/saveFile")
public String saveFile(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request, Model model) {
System.out.println("开始");
String path = request.getSession().getServletContext().getRealPath("/upload");
String fileName = file.getOriginalFilename();
System.out.println(path);
File targetFile = new File(path, fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
//保存
try {
file.transferTo(targetFile);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
如果也想学习本系统,下面领取。关注并回复:078ssm