当前位置:   article > 正文

Java项目:SSM自习室图书馆座位预约管理系统_图书预约管理系统csdn

图书预约管理系统csdn

作者主页:夜未央5788

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

文末获取源码

项目介绍

一款由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项目:否;

技术栈

1. 后端:Spring+SpringMVC+Mybatis

2. 前端:JSP+easyUI

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中config.properties配置文件中的数据库配置改为自己的配置;

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

运行截图

管理员角色

教师角色

学生角色

相关代码

BlockController

  1. package dingzhen.controller;
  2. // 查看余坐
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.List;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import net.sf.json.JSONArray;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import dingzhen.entity.Room;
  15. import dingzhen.entity.Seat;
  16. import dingzhen.service.RoomService;
  17. import dingzhen.service.SeatService;
  18. import dingzhen.util.WriterUtil;
  19. @Controller
  20. @RequestMapping("block")
  21. public class BlockController {
  22. @Autowired
  23. private RoomService<Room> roomService;
  24. private Seat seat;
  25. @Autowired
  26. private SeatService<Seat> seatService;
  27. @RequestMapping("blockList")
  28. public void list(HttpServletResponse response,HttpServletRequest request) {
  29. try {
  30. String[] times = new String[]{"08点-12点","14点-18点","18点-22点"};
  31. Date today = new Date();
  32. Date tomorrow = getNextDay(today, 1);
  33. Date[] dates = new Date[]{today,tomorrow};
  34. List<Room> rooms = roomService.findRoom(new Room());
  35. List<Seat> list = new ArrayList<Seat>();
  36. for(int j=0;j<dates.length;j++){
  37. Date date = dates[j];
  38. for(int i=0;i<times.length;i++){
  39. String time = times[i];
  40. for(int k=0;k<rooms.size();k++){
  41. int roomid = rooms.get(k).getId();
  42. seat = new Seat();
  43. seat.setRoomid(roomid);
  44. seat.setDate(new SimpleDateFormat("yyyy-MM-dd").format(date));
  45. seat.setTime(time);
  46. seat.setRoomname(rooms.get(k).getName());
  47. int yuzuo = seatService.findBlock(seat);
  48. seat.setPage(yuzuo); //将page字段临时存放余坐
  49. list.add(seat);
  50. }
  51. }
  52. }
  53. JSONArray array = new JSONArray();
  54. array.addAll(list);
  55. WriterUtil.write(response, array.toString());
  56. } catch (Exception e) {
  57. e.printStackTrace();
  58. }
  59. }
  60. @RequestMapping("blockIndex")
  61. public String block(){
  62. return "seat/block";
  63. }
  64. public static Date getNextDay(Date date,int day) {
  65. Calendar calendar = Calendar.getInstance();
  66. calendar.setTime(date);
  67. calendar.add(Calendar.DAY_OF_MONTH, day);
  68. date = calendar.getTime();
  69. return date;
  70. }
  71. }

登录控制器

  1. package dingzhen.controller;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import javax.servlet.http.HttpSession;
  8. import net.sf.json.JSONArray;
  9. import net.sf.json.JSONObject;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import dingzhen.util.StringUtil;
  14. import dingzhen.util.WriterUtil;
  15. import dingzhen.entity.Menu;
  16. import dingzhen.entity.Role;
  17. import dingzhen.entity.User;
  18. import dingzhen.service.MenuService;
  19. import dingzhen.service.RoleService;
  20. import dingzhen.service.UserService;
  21. /**
  22. * 登录
  23. */
  24. @Controller
  25. @SuppressWarnings("unchecked")
  26. public class LoginController {
  27. private User user;
  28. private User currentUser;
  29. @Autowired
  30. private UserService<User> userService;
  31. @Autowired
  32. private MenuService<Menu> menuService;
  33. private Role role;
  34. @Autowired
  35. private RoleService<Role> roleService;
  36. private Map map;
  37. @RequestMapping("login")
  38. public void login(HttpServletRequest request,HttpServletResponse response){
  39. try {
  40. HttpSession session = request.getSession();
  41. String userName=request.getParameter("userName");
  42. String password=request.getParameter("password");
  43. String imageCode=request.getParameter("imageCode");
  44. request.setAttribute("userName", userName);
  45. request.setAttribute("password", password);
  46. request.setAttribute("imageCode", imageCode);
  47. if(StringUtil.isEmpty(userName)||StringUtil.isEmpty(password)){
  48. request.setAttribute("error", "账户或密码为空");
  49. request.getRequestDispatcher("login.jsp").forward(request, response);
  50. return;
  51. }
  52. if(StringUtil.isEmpty(imageCode)){
  53. request.setAttribute("error", "验证码为空");
  54. request.getRequestDispatcher("login.jsp").forward(request, response);
  55. return;
  56. }
  57. if(!imageCode.equals(session.getAttribute("sRand"))){
  58. request.setAttribute("error", "验证码错误");
  59. request.getRequestDispatcher("login.jsp").forward(request, response);
  60. return;
  61. }
  62. map = new HashMap<String, String>();
  63. map.put("userName", userName);
  64. map.put("password", password);
  65. currentUser = userService.loginUser(map);
  66. if(currentUser==null){
  67. request.setAttribute("error", "用户名或密码错误");
  68. request.getRequestDispatcher("login.jsp").forward(request, response);
  69. }else{
  70. role = roleService.findOneRole(currentUser.getRoleId());
  71. String roleName=role.getRoleName();
  72. currentUser.setRoleName(roleName);
  73. session.setAttribute("currentUser", currentUser);
  74. session.setAttribute("currentOperationIds", role.getOperationIds());
  75. response.sendRedirect("main.htm");
  76. }
  77. } catch (Exception e) {
  78. e.printStackTrace();
  79. }
  80. }
  81. // 进入系统主界面
  82. @RequestMapping("main")
  83. public String toMain(HttpServletRequest request){
  84. Object attribute = request.getSession().getAttribute("currentUser");
  85. if(attribute == null){
  86. return "redirect:login.htm";
  87. }
  88. //return "main";
  89. return "sys/main";
  90. }
  91. // 加载最上级左菜单树
  92. @RequestMapping("menuTree")
  93. public void getMenuTree(HttpServletRequest request,HttpServletResponse response){
  94. try {
  95. String parentId = request.getParameter("parentId");
  96. currentUser = (User) request.getSession().getAttribute("currentUser");
  97. role = roleService.findOneRole(currentUser.getRoleId());
  98. String[] menuIds = role.getMenuIds().split(",");
  99. map = new HashMap();
  100. map.put("parentId",parentId);
  101. map.put("menuIds", menuIds);
  102. JSONArray jsonArray = getMenusByParentId(parentId, menuIds);
  103. WriterUtil.write(response, jsonArray.toString());
  104. } catch (Exception e) {
  105. e.printStackTrace();
  106. }
  107. }
  108. // 递归加载所所有树菜单
  109. public JSONArray getMenusByParentId(String parentId,String[] menuIds)throws Exception{
  110. JSONArray jsonArray=this.getMenuByParentId(parentId,menuIds);
  111. for(int i=0;i<jsonArray.size();i++){
  112. JSONObject jsonObject=jsonArray.getJSONObject(i);
  113. if("open".equals(jsonObject.getString("state"))){
  114. continue;
  115. }else{
  116. jsonObject.put("children", getMenusByParentId(jsonObject.getString("id"),menuIds));
  117. }
  118. }
  119. return jsonArray;
  120. }
  121. // 将所有的树菜单放入easyui要求格式的json
  122. public JSONArray getMenuByParentId(String parentId,String[] menuIds)throws Exception{
  123. JSONArray jsonArray=new JSONArray();
  124. map= new HashMap();
  125. map.put("parentId",parentId);
  126. map.put("menuIds", menuIds);
  127. List<Menu> list = menuService.menuTree(map);
  128. for(Menu menu : list){
  129. JSONObject jsonObject = new JSONObject();
  130. jsonObject.put("id", menu.getMenuId());
  131. jsonObject.put("text", menu.getMenuName());
  132. jsonObject.put("iconCls", menu.getIconCls());
  133. JSONObject attributeObject = new JSONObject();
  134. attributeObject.put("menuUrl", menu.getMenuUrl());
  135. if(!hasChildren(menu.getMenuId(), menuIds)){
  136. jsonObject.put("state", "open");
  137. }else{
  138. jsonObject.put("state", menu.getState());
  139. }
  140. jsonObject.put("attributes", attributeObject);
  141. jsonArray.add(jsonObject);
  142. }
  143. return jsonArray;
  144. }
  145. // 判断是不是有子孩子,人工结束递归树
  146. public boolean hasChildren(Integer parentId,String[] menuIds){
  147. boolean flag = false;
  148. try {
  149. map= new HashMap();
  150. map.put("parentId",parentId);
  151. map.put("menuIds", menuIds);
  152. List<Menu> list = menuService.menuTree(map);
  153. if (list == null || list.size()==0) {
  154. flag = false;
  155. }else {
  156. flag = true;
  157. }
  158. } catch (Exception e) {
  159. e.printStackTrace();
  160. }
  161. return flag;
  162. }
  163. // 更新密码
  164. @RequestMapping("updatePassword")
  165. public void updatePassword(HttpServletRequest request,HttpServletResponse response){
  166. JSONObject result=new JSONObject();
  167. try {
  168. String userId=request.getParameter("userId");
  169. String newPassword=request.getParameter("newPassword");
  170. user=new User();
  171. user.setUserId(Integer.parseInt(userId));
  172. user.setPassword(newPassword);
  173. userService.updateUser(user);
  174. result.put("success", "true");
  175. } catch (Exception e) {
  176. e.printStackTrace();
  177. result.put("success", "true");
  178. result.put("errorMsg", "对不起!密码修改失败");
  179. }
  180. WriterUtil.write(response, result.toString());
  181. }
  182. //安全退出
  183. @SuppressWarnings("unused")
  184. @RequestMapping("logout")
  185. private void logout(HttpServletRequest request,HttpServletResponse response) throws Exception{
  186. request.getSession().invalidate();
  187. response.sendRedirect("login.jsp");
  188. }
  189. }

阅览室控制器

  1. package dingzhen.controller;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.List;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import net.sf.json.JSONArray;
  8. import net.sf.json.JSONObject;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import dingzhen.entity.Room;
  13. import dingzhen.entity.Seat;
  14. import dingzhen.service.RoomService;
  15. import dingzhen.service.SeatService;
  16. import dingzhen.util.StringUtil;
  17. import dingzhen.util.WriterUtil;
  18. // 阅览室基本信息
  19. @RequestMapping("room")
  20. @Controller
  21. public class RoomController {
  22. private int page;
  23. private int rows;
  24. private Room room;
  25. @Autowired
  26. private RoomService<Room> roomService;
  27. @Autowired
  28. private SeatService<Seat> seatService;
  29. @RequestMapping("roomIndex")
  30. public String index(){
  31. return "readingroom/room";
  32. }
  33. @RequestMapping("roomList")
  34. public void roomList(HttpServletRequest request,HttpServletResponse response) {
  35. try {
  36. page = Integer.parseInt(request.getParameter("page"));
  37. rows = Integer.parseInt(request.getParameter("rows"));
  38. room = new Room();
  39. if(request.getParameter("typeid")!=null && request.getParameter("typeid").length() > 0){
  40. room.setTypeid(Integer.parseInt(request.getParameter("typeid")));
  41. }
  42. room.setPage((page-1)*rows);
  43. room.setRows(rows);
  44. List<Room> list = roomService.findRoom(room);
  45. int total = roomService.countRoom(room);
  46. JSONObject jsonObj = new JSONObject();//new一个JSON
  47. jsonObj.put("total",total );//total代表一共有多少数据
  48. jsonObj.put("rows", list);//row是代表显示的页的数据
  49. WriterUtil.write(response,jsonObj.toString()); //将上述Json输出,前台ajax接收
  50. } catch (Exception e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. @RequestMapping("reserveRoom")
  55. public void reserveroom(HttpServletRequest request,HttpServletResponse response,Room room) {
  56. String id = request.getParameter("id");
  57. room.setTotal(room.getCol() * room.getRow()); //总座位数=列数 X 行数
  58. JSONObject result = new JSONObject();
  59. result.put("success", true);
  60. try {
  61. if(StringUtil.isNotEmpty(id)){
  62. room.setId(Integer.parseInt(id));
  63. roomService.updateRoom(room);
  64. } else {
  65. roomService.addRoom(room);
  66. /**int row=room.getRow();
  67. int cal=room.getCol();
  68. for(int rown=1; rown<=row; rown++) {
  69. for(int caln=1;caln<=cal;caln++) {
  70. Seat seat = new Seat();
  71. seat.setCol(caln);
  72. seat.setRow(rown);
  73. seat.setDate(id);
  74. seat.setStudentno("1");
  75. seatService.occupySeat(seat);
  76. }
  77. }**/
  78. int row=room.getRow();
  79. int cal=room.getCol();
  80. for(int rown=1; rown<=row; rown++) {
  81. for(int caln=1;caln<=cal;caln++) {
  82. try {
  83. Seat seat = new Seat();
  84. seat.setCol(caln);
  85. seat.setRow(rown);
  86. seat.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
  87. int roomid=roomService.getFinal();
  88. seat.setRoomid(roomid);
  89. seat.setTime("08点-12点");
  90. seat.setKeyword(new SimpleDateFormat("yyyy-MM-dd").format(new Date())+"-08点-12点-"+roomid+"-"+rown+"-"+caln);
  91. //2021-05-14-08点-12点-24-9-9
  92. seatService.insertSeat(seat);
  93. } catch (Exception e) {
  94. e.printStackTrace();
  95. }
  96. }}
  97. }
  98. } catch (Exception e) {
  99. e.printStackTrace();
  100. result.put("errorMsg", "对不起!保存失败");
  101. }
  102. WriterUtil.write(response,result.toString());
  103. }
  104. @RequestMapping("deleteRoom")
  105. public void delete(HttpServletRequest request,HttpServletResponse response){
  106. JSONObject result=new JSONObject();
  107. try {
  108. String[] ids=request.getParameter("ids").split(",");
  109. for (String id : ids) {
  110. roomService.deleteRoom(Integer.parseInt(id));
  111. }
  112. result.put("success", true);
  113. result.put("delNums", ids.length);
  114. } catch (Exception e) {
  115. e.printStackTrace();
  116. result.put("errorMsg", "对不起,删除失败");
  117. }
  118. WriterUtil.write(response, result.toString());
  119. }
  120. }

如果也想学习本系统,下面领取。关注并回复:171ssm

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/530536
推荐阅读
相关标签
  

闽ICP备14008679号