基于javaweb+mysql的ssm自习室图书馆座位预约管理系统(java+ssm+jsp+easyui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM自习室图书馆座位预约管理系统(java+ssm+jsp+easyui+mysql)
项目介绍
一款由jsp+ssm+mysql实现的图书馆预约占座管理系统,前端采用的是当下最流行的easyui框架,后台用的ssm(spring、springMVC、mybaits)框架.添加学生和教师时会自动在用户表中注册,定时任务会定时生成座位信息,阅览室分类中可设置信用等级,学生被扣分后信用等级低于相应的值后不能预约相应的阅览室座位.本项目分为管理员、教师、学生三种角色。
管理员角色包含以下功能: 管理员登陆,用户管理,师生信息管理,阅览室管理,信用积分管理,交流管理,信息统计,图书推荐等功能。
教师角色包含以下功能: 教师角色登陆,个人信息管理,管理学生的信用积分等功能。
学生角色包含以下功能: 学生账号登陆,阅览室信息查看,信息积分查看,选座位,选座管理,通知信息管理,信息交流,图书推荐等功能。
环境需要
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项目:否;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+easyUI
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中config.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ 登录
for (String id : ids) {
user = userService.findOneUser(Integer.parseInt(id));
userService.deleteUser(Integer.parseInt(id));
}
result.put("success", true);
result.put("delNums", ids.length);
} catch (Exception e) {
e.printStackTrace();
result.put("errorMsg", "对不起,删除失败");
}
WriterUtil.write(response, result.toString());
}
}
// 学生违规控制器
@Controller
@RequestMapping("illegal")
public class IllegalController {
private int page;
private int rows;
private Illegal illegal;
@Autowired
private IllegalService<Illegal> illegalService;
@Autowired
private ScoreService<Score> scoreService;
private Score score;
@RequestMapping("illegalList")
public void illegalList(HttpServletRequest request,HttpServletResponse response){
try {
page = Integer.parseInt(request.getParameter("page"));
rows = Integer.parseInt(request.getParameter("rows"));
illegal = new Illegal();
Film obj = null;//影片对象
if(id != null){
//删除前先查询出影片对象
obj = filmService.getFilmById(id);
}
//执行删除影片操作
result = pjp.proceed();
if(obj != null){
//创建日志对象
Log log = new Log();
log.setUserid(logService.loginUserId());//用户编号
log.setCreatedate(new Date());//操作时间
StringBuffer msg = new StringBuffer("影片名 : ");
msg.append(obj.getFname());
log.setContent(msg.toString());//操作内容
log.setOperation("删除");//操作
logService.log(log);//添加日志
}
}
catch(Exception ex) {
ex.printStackTrace();
}
return result;
}
*/
/**
* 反射获得对象信息
* @param o
* @return
*/
public static String getFieldsInfo(Object o){
Field[] fields = o.getClass().getDeclaredFields();
//String[] fieldNames = new String[fields.length];
StringBuffer sb = new StringBuffer("属性名和值:");
/**
* 遍历所有字段
* 从下标1开始
* 把0位置的serialVersionUID过滤掉
* 所以要求实体类的第一个属性都是serial*UID
*/
for (int i = 1; i < fields.length; i++) {
sb.append(fields[i].getName()+ "-->"+getFieldValueByName(fields[i].getName(), o)+" ");
* @throws Throwable
*/
@AfterReturning(value="addServiceCall()", argNames="rtv", returning="rtv")
public void insertServiceCallCalls(JoinPoint joinPoint, Object rtv) throws Throwable{
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
User currentUser = (User) request.getSession().getAttribute("currentUser");
//判断参数
if(joinPoint.getArgs() == null){//没有参数
return;
}
//获取方法名
//String methodName = joinPoint.getSignature().getName();
String className = joinPoint.getArgs()[0].getClass().getName();
//获取操作内容
className = className.substring(className.lastIndexOf(".") + 1);
String opContent = adminOptionContent(joinPoint.getArgs(), "添加");
//创建日志对象
Log log = new Log();
log.setModule(className.toLowerCase());
try {
log.setUserName(currentUser.getUserName());
} catch (Exception e) {
log.setUserName("开发者");
}
log.setCreateTime(TimeUtil.formatTime(new Date(),"yyyy-MM-dd HH:mm:ss"));//操作时间
log.setContent(opContent);//操作内容
log.setOperation("添加");//操作
log.setIp(getIpAddr(request));
logService.insertLog(log);
}
/**
* 管理员修改操作日志(后置通知)
* @param joinPoint
* @param rtv
* @throws Throwable
*/
@AfterReturning(value="updateServiceCall()", argNames="rtv", returning="rtv")
public void updateServiceCallCalls(JoinPoint joinPoint, Object rtv) throws Throwable{
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
User currentUser = (User) request.getSession().getAttribute("currentUser");
@RequestMapping("chart")
@Controller
public class ChartController {
@Autowired
private IllegalService<Illegal> illegalService;
private Illegal illegal;
private Room room;
@Autowired
private RoomService<Room> roomService;
private Seat seat;
jsonObj.put("total",total );
jsonObj.put("rows", list);
WriterUtil.write(response,jsonObj.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 记录日志
* @param operation
* @param module
* @param request
* @param o
*/
public void addLog(String operation,String module,HttpServletRequest request,Object o){
try {
log = new Log();
log.setContent(getFieldsInfo(o));
log.setOperation(operation);
log.setIp(getIpAddr(request));
log.setCreateTime(TimeUtil.formatTime(new Date(), "yyyy-MM-dd HH:mm:ss"));
User currentUser = (User)request.getSession().getAttribute("currentUser");
log.setUserName(currentUser.getUserName());
log.setModule(module);
logService.insertLog(log);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取访问者IP
*
* 在一般情况下使用Request.getRemoteAddr()即可,但是经过nginx等反向代理软件后,这个方法会失效。
*
* 本方法先从Header中获取X-Real-IP,如果不存在再从X-Forwarded-For获得第一个IP(用,分割),
* 如果还不存在则调用Request .getRemoteAddr()。
*
* @param request
* @return
*/
public static String getIpAddr(HttpServletRequest request) throws Exception{
String ip = request.getHeader("X-Real-IP");
if (!StringUtil.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip)) {
return ip;
String roleId = request.getParameter("roleId");
if (StringUtil.isNotEmpty(roleId)) {
user.setRoleId(Integer.parseInt(roleId));
} else {
user.setRoleId(null);
}
List<User> list = userService.findUser(user);
int total = userService.countUser(user);
JSONObject jsonObj = new JSONObject();//new一个JSON
jsonObj.put("total",total );//total代表一共有多少数据
jsonObj.put("rows", list);//row是代表显示的页的数据
WriterUtil.write(response,jsonObj.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
// 新增或修改
@RequestMapping("reserveUser")
public void reserveUser(HttpServletRequest request,User user,HttpServletResponse response){
String userId = request.getParameter("userId");
JSONObject result=new JSONObject();
try {
if (StringUtil.isNotEmpty(userId)) { // userId不为空 说明是修改
user.setUserId(Integer.parseInt(userId));
userService.updateUser(user);
result.put("success", true);
}else { // 添加
if(userService.existUserWithUserName(user.getUserName())==null){ // 没有重复可以添加
userService.addUser(user);
result.put("success", true);
} else {
result.put("success", true);
result.put("errorMsg", "该用户名被使用");
}
}
} catch (Exception e) {
e.printStackTrace();
result.put("success", true);
result.put("errorMsg", "对不起,操作失败");
}
WriterUtil.write(response, result.toString());
}
@RequestMapping("deleteUser")
public void delUser(HttpServletRequest request,HttpServletResponse response){
JSONObject result=new JSONObject();
try {
String[] ids=request.getParameter("ids").split(",");
for (String id : ids) {
user = userService.findOneUser(Integer.parseInt(id));
userService.deleteUser(Integer.parseInt(id));
List<Operation> list = operationService.findOperation(operation);
for(Operation operation : list){
JSONObject jsonObject = new JSONObject();
int operationId = operation.getOperationId();
jsonObject.put("id", operationId);
jsonObject.put("text", operation.getOperationName());
jsonObject.put("iconCls", "");
jsonObject.put("state", "open");
if (StringUtil.isNotEmpty(operationIds)) {
if (dingzhen.util.StringUtil.existStrArr(operationId+"", operationIds.split(","))) {
jsonObject.put("checked", true);
}
}
jsonArray.add(jsonObject);
}
return jsonArray;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@RequestMapping("updateRoleMenu")
public void updateRoleMenu(HttpServletRequest request,HttpServletResponse response){
JSONObject result = new JSONObject();
try {
String roleId = request.getParameter("roleId");
String[] ids = request.getParameter("menuIds").split(",");
String menuIds = "";
String operationIds = "";
/**
* 采用的方案是在菜单递归之后,再加上各菜单下的按钮
* 采用easyui的解析方式所以字段都用的是id和text。
* 为了区别两者,我们规定operationId自增从10000开始
* menuId从1开始,在上传过来的ids中是这样的形式
* 2,10000,3,4,7,10004,10006,45 这样的菜单ID和按钮ID的混合形式
if(StringUtil.isEmpty(userName)||StringUtil.isEmpty(password)){
request.setAttribute("error", "账户或密码为空");
request.getRequestDispatcher("login.jsp").forward(request, response);
return;
}
if(StringUtil.isEmpty(imageCode)){
request.setAttribute("error", "验证码为空");
request.getRequestDispatcher("login.jsp").forward(request, response);
return;
}
if(!imageCode.equals(session.getAttribute("sRand"))){
request.setAttribute("error", "验证码错误");
request.getRequestDispatcher("login.jsp").forward(request, response);
return;
}
map = new HashMap<String, String>();
map.put("userName", userName);
map.put("password", password);
currentUser = userService.loginUser(map);
if(currentUser==null){
request.setAttribute("error", "用户名或密码错误");
request.getRequestDispatcher("login.jsp").forward(request, response);
}else{
role = roleService.findOneRole(currentUser.getRoleId());
String roleName=role.getRoleName();
currentUser.setRoleName(roleName);
session.setAttribute("currentUser", currentUser);
session.setAttribute("currentOperationIds", role.getOperationIds());
response.sendRedirect("main.htm");
}
} catch (Exception e) {
e.printStackTrace();
}
}
// 进入系统主界面
@RequestMapping("main")
public String toMain(HttpServletRequest request){
Object attribute = request.getSession().getAttribute("currentUser");
if(attribute == null){
return "redirect:login.htm";
}
List<Room> list = roomService.findRoom(new Room());
JSONArray array = new JSONArray();
array.addAll(list);
WriterUtil.write(response, array.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
//查找自己的作为
@RequestMapping("myselfSeat")
public void myselfSeat(HttpServletRequest request,HttpServletResponse response){
User currentUser = (User)request.getSession().getAttribute("currentUser");
try {
String date = request.getParameter("date");
if(date==null || date.length()==0){
date = (new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
}
String roomid = request.getParameter("roomid");
if(roomid==null || roomid.length()==0){
roomid = "1";
}
String time = request.getParameter("time");
if(time == null || time.length()==0){
time = "08点-12点";
}
Choice c = new Choice();
c.setSeatkeyword(date + "-" +time + "-" +roomid);
c.setStudentno(currentUser.getUserName());
choice = choiceService.findOneChoice(c);
if(choice == null){
WriterUtil.write(response, "no");
} else {
WriterUtil.write(response, choice.getSeatkeyword());
}
} catch (Exception e) {
e.printStackTrace();
}
}
// 保存选中座位
@RequestMapping("saveSeat")
public void saveSeat(HttpServletRequest request,HttpServletResponse response) {
String keyword = request.getParameter("keyword");
System.out.println("key---"+keyword);
User currentUser = (User)request.getSession().getAttribute("currentUser");
@RequestMapping("main")
public String toMain(HttpServletRequest request){
Object attribute = request.getSession().getAttribute("currentUser");
if(attribute == null){
return "redirect:login.htm";
}
//return "main";
return "sys/main";
}
// 加载最上级左菜单树
@RequestMapping("menuTree")
public void getMenuTree(HttpServletRequest request,HttpServletResponse response){
try {
String parentId = request.getParameter("parentId");
currentUser = (User) request.getSession().getAttribute("currentUser");
role = roleService.findOneRole(currentUser.getRoleId());
String[] menuIds = role.getMenuIds().split(",");
map = new HashMap();
map.put("parentId",parentId);
map.put("menuIds", menuIds);
JSONArray jsonArray = getMenusByParentId(parentId, menuIds);
WriterUtil.write(response, jsonArray.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
// 递归加载所所有树菜单
public JSONArray getMenusByParentId(String parentId,String[] menuIds)throws Exception{
JSONArray jsonArray=this.getMenuByParentId(parentId,menuIds);
for(int i=0;i<jsonArray.size();i++){
JSONObject jsonObject=jsonArray.getJSONObject(i);
if("open".equals(jsonObject.getString("state"))){
continue;
}else{
jsonObject.put("children", getMenusByParentId(jsonObject.getString("id"),menuIds));
}
}
return jsonArray;
}
// 将所有的树菜单放入easyui要求格式的json
public JSONArray getMenuByParentId(String parentId,String[] menuIds)throws Exception{
JSONArray jsonArray=new JSONArray();
map= new HashMap();
map.put("parentId",parentId);
map.put("menuIds", menuIds);
List<Menu> list = menuService.menuTree(map);
for(Menu menu : list){
JSONObject jsonObject = new JSONObject();
* @param request
* @param response
* @param times
* @param floors
* @param data
* @param subTitle
* @param width
*/
private void bar(HttpServletRequest request, HttpServletResponse response,
String[] times, String[] floors, double[][] data, String title,String subTitle,int width) {
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(floors,times,data);
JFreeChart chart = ChartFactory.createBarChart3D(title, "时间", "人数",
dataset, PlotOrientation.VERTICAL, true, true, true); // 创建柱状图模型
// 副标题
chart.addSubtitle(new TextTitle(subTitle));
CategoryPlot plot = chart.getCategoryPlot();
// 设置网格背景颜色
plot.setBackgroundPaint(Color.white);
// 设置网格竖线颜色
plot.setDomainGridlinePaint(Color.pink);
// 设置网格横线颜色
plot.setRangeGridlinePaint(Color.pink);
// 显示每个柱的数值,并修改该数值的字体属性
BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setBaseItemLabelsVisible(true);
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
renderer.setItemLabelAnchorOffset(10D);
// 设置平行柱的之间距离
renderer.setItemMargin(0.4);
plot.setRenderer(renderer);
// 将图表以数据流的方式返回给客户端
try {
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart,
width, 350); // 500,300是长和宽
} catch (IOException e) {
e.printStackTrace();
}
}
if(time == null || time.length()==0){
seat.setTime("08点-12点");
}else {
seat.setTime(time);
}
List<Seat> list = seatService.findSeat(seat);
JSONArray array = new JSONArray();
array.addAll(list);
WriterUtil.write(response, array.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
// 今天和明天
@RequestMapping("dateCombo")
public void dateCombo(HttpServletRequest request,HttpServletResponse response){
try {
// 获取今明两天时间的String值。格式是yyyy-MM-dd
Date todayDate = new Date();
Date tomorrowDate = getNextDay(todayDate);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String today = sdf.format(todayDate);
String tomorrow = sdf.format(tomorrowDate);
List<ComboValue> list = new ArrayList<ComboValue>();
ComboValue cv = new ComboValue(today, "今天 "+today);
list.add(cv);
ComboValue cv2 = new ComboValue(tomorrow, "明天 "+tomorrow);
list.add(cv2);
JSONArray array = new JSONArray();
array.addAll(list);
WriterUtil.write(response, array.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
// 获取明天日期
public static Date getNextDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, 1);
date = calendar.getTime();
@Autowired
private IllegalService<Illegal> illegalService;
private Illegal illegal;
private Room room;
@Autowired
private RoomService<Room> roomService;
private Seat seat;
@Autowired
private SeatService<Seat> seatService;
@Autowired
private ChoiceService<Choice> choiceService;
// 进入违规统计
@RequestMapping("illegalChart")
public String illegalIndex(){
return "chart/illegal";
}
// 违规统计表
@RequestMapping("findIllegalChart")
public void findIllegalChart(HttpServletRequest request,HttpServletResponse response){
try {
double[][] data = new double[1][12]; //一年12月
String[] months = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
for(int i=1;i<13;i++){
// 每月违规人数
String start = getCurrentYear();
String end = getCurrentYear();
if(i<10){
start = start + "-0" + i +"-01 00:00:01";
end = end + "-0" + i + "-31 23:59:59";
} else {
start = start + "-" + i +"-01 00:00:01";
end = end + "-" + i + "-31 23:59:59";
}
illegal = new Illegal();
illegal.setStart(start);
illegal.setEnd(end);
int total = illegalService.countIllegal(illegal);
data[0][i-1] = total;
}
bar(request, response, months, new String[]{"违规人数"}, data,getCurrentYear()+"全年度违规人数统计", "违规人数统计", 750);
} catch (Exception e) {
e.printStackTrace();
String parentId = request.getParameter("parentId");
if (!isLeaf(menuId)) { //不是叶子节点,说明有子菜单,不能删除
result.put("errorMsg", "该菜单下面有子菜单,不能直接删除");
} else {
menu = new Menu();
menu.setParentId(Integer.parseInt(parentId));
int sonNum = menuService.countMenu(menu);
if (sonNum == 1) {
// 只有一个孩子,删除该孩子,且把父亲状态置为open
menu = new Menu();
menu.setMenuId(Integer.parseInt(parentId));
menu.setState("open");
menuService.updateMenu(menu);
menuService.deleteMenu(Integer.parseInt(menuId));
} else {
//不只一个孩子,直接删除
menuService.deleteMenu(Integer.parseInt(menuId));
}
result.put("success", true);
}
} catch (Exception e) {
e.printStackTrace();
result.put("errorMsg", "对不起,删除失败!");
}
WriterUtil.write(response, result.toString());
}
}
} else {
return ip;
}
} else {
return request.getRemoteAddr();
}
}
/**
* 通过反射
* 根据字段名称获取字段值
* @param fieldName
* @param o
* @return
*/
private static Object getFieldValueByName(String fieldName,Object o){
try {
String firstLetter = fieldName.substring(0, 1).toUpperCase(); //手写字母大写
String getter = "get" + firstLetter + fieldName.substring(1); // get方法
Method method = o.getClass().getMethod(getter,new Class[]{});
Object object = method.invoke(o, new Object[]{});
return object;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 反射获得字段值
* @param o
* @return
*/
@SuppressWarnings("unused")
private static String[] getFieldName(Object o){
Field[] fields = o.getClass().getDeclaredFields();
String[] fieldNames = new String[fields.length];
for (int i = 0; i < fieldNames.length; i++) {
fieldNames[i] = fields[i].getName();
}
return fieldNames;
}
WriterUtil.write(response, result.toString());
}
@RequestMapping("chooseMenu")
public void chooseMenu(HttpServletRequest request,HttpServletResponse response){
try {
String parentId=request.getParameter("parentId");
String roleId=request.getParameter("roleId");
role = roleService.findOneRole(Integer.parseInt(roleId));
String menuIds = role.getMenuIds();
String operationIds = role.getOperationIds();
JSONArray jsonArray=getCheckedMenusByParentId(parentId, menuIds,operationIds);
WriterUtil.write(response, jsonArray.toString());
System.out.println(jsonArray.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
// 选中已有的角色
public JSONArray getCheckedMenusByParentId(String parentId,String menuIds,String operationIds)throws Exception{
JSONArray jsonArray=this.getCheckedMenuByParentId(parentId,menuIds,operationIds);
for(int i=0;i<jsonArray.size();i++){
JSONObject jsonObject=jsonArray.getJSONObject(i);
if("open".equals(jsonObject.getString("state"))){
continue;
}else{
jsonObject.put("children", getCheckedMenusByParentId(jsonObject.getString("id"),menuIds,operationIds));
}
}
return jsonArray;
}
public JSONArray getCheckedMenuByParentId(String parentId,String menuIds,String operationIds)throws Exception{
JSONArray jsonArray=new JSONArray();
menu = new Menu();
menu.setParentId(Integer.parseInt(parentId));
List<Menu> list = menuService.findMenu(menu);
for(Menu menu : list){
JSONObject jsonObject = new JSONObject();
/**
* 日志管理控制器
*/
@Controller
@RequestMapping("log")
public class LogController {
private Log log;
private int page = 1;
private int rows = 10;
@Autowired
private LogService<Log> logService;
@RequestMapping("logIndex")
public String index(){
return "sys/log";
}
@RequestMapping("logList")
public void logList(HttpServletRequest request,HttpServletResponse response){
try {
page = Integer.parseInt(request.getParameter("page"));
rows = Integer.parseInt(request.getParameter("rows"));
log = new Log();
log.setModule(request.getParameter("module"));