赞
踩
作者主页:夜未央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/ 登录
- package dingzhen.controller;
-
- // 查看余坐
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import net.sf.json.JSONArray;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
-
- import dingzhen.entity.Room;
- import dingzhen.entity.Seat;
- import dingzhen.service.RoomService;
- import dingzhen.service.SeatService;
- import dingzhen.util.WriterUtil;
-
- @Controller
- @RequestMapping("block")
- public class BlockController {
-
- @Autowired
- private RoomService<Room> roomService;
- private Seat seat;
- @Autowired
- private SeatService<Seat> seatService;
-
-
- @RequestMapping("blockList")
- public void list(HttpServletResponse response,HttpServletRequest request) {
- try {
- String[] times = new String[]{"08点-12点","14点-18点","18点-22点"};
- Date today = new Date();
- Date tomorrow = getNextDay(today, 1);
- Date[] dates = new Date[]{today,tomorrow};
- List<Room> rooms = roomService.findRoom(new Room());
- List<Seat> list = new ArrayList<Seat>();
- for(int j=0;j<dates.length;j++){
- Date date = dates[j];
- for(int i=0;i<times.length;i++){
- String time = times[i];
- for(int k=0;k<rooms.size();k++){
- int roomid = rooms.get(k).getId();
- seat = new Seat();
- seat.setRoomid(roomid);
- seat.setDate(new SimpleDateFormat("yyyy-MM-dd").format(date));
- seat.setTime(time);
- seat.setRoomname(rooms.get(k).getName());
- int yuzuo = seatService.findBlock(seat);
- seat.setPage(yuzuo); //将page字段临时存放余坐
- list.add(seat);
- }
- }
- }
- JSONArray array = new JSONArray();
- array.addAll(list);
- WriterUtil.write(response, array.toString());
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
-
- @RequestMapping("blockIndex")
- public String block(){
- return "seat/block";
- }
-
- public static Date getNextDay(Date date,int day) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- calendar.add(Calendar.DAY_OF_MONTH, day);
- date = calendar.getTime();
- return date;
- }
-
-
- }
- package dingzhen.controller;
-
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
-
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
-
- import dingzhen.util.StringUtil;
- import dingzhen.util.WriterUtil;
- import dingzhen.entity.Menu;
- import dingzhen.entity.Role;
- import dingzhen.entity.User;
- import dingzhen.service.MenuService;
- import dingzhen.service.RoleService;
- import dingzhen.service.UserService;
-
- /**
- * 登录
- */
- @Controller
- @SuppressWarnings("unchecked")
- public class LoginController {
-
- private User user;
- private User currentUser;
- @Autowired
- private UserService<User> userService;
- @Autowired
- private MenuService<Menu> menuService;
- private Role role;
- @Autowired
- private RoleService<Role> roleService;
- private Map map;
-
- @RequestMapping("login")
- public void login(HttpServletRequest request,HttpServletResponse response){
- try {
- HttpSession session = request.getSession();
- String userName=request.getParameter("userName");
- String password=request.getParameter("password");
- String imageCode=request.getParameter("imageCode");
- request.setAttribute("userName", userName);
- request.setAttribute("password", password);
- request.setAttribute("imageCode", imageCode);
- 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";
- }
- //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();
- jsonObject.put("id", menu.getMenuId());
- jsonObject.put("text", menu.getMenuName());
- jsonObject.put("iconCls", menu.getIconCls());
- JSONObject attributeObject = new JSONObject();
- attributeObject.put("menuUrl", menu.getMenuUrl());
- if(!hasChildren(menu.getMenuId(), menuIds)){
- jsonObject.put("state", "open");
- }else{
- jsonObject.put("state", menu.getState());
- }
- jsonObject.put("attributes", attributeObject);
- jsonArray.add(jsonObject);
- }
- return jsonArray;
- }
-
-
- // 判断是不是有子孩子,人工结束递归树
- public boolean hasChildren(Integer parentId,String[] menuIds){
- boolean flag = false;
- try {
- map= new HashMap();
- map.put("parentId",parentId);
- map.put("menuIds", menuIds);
- List<Menu> list = menuService.menuTree(map);
- if (list == null || list.size()==0) {
- flag = false;
- }else {
- flag = true;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return flag;
- }
-
-
-
-
- // 更新密码
- @RequestMapping("updatePassword")
- public void updatePassword(HttpServletRequest request,HttpServletResponse response){
- JSONObject result=new JSONObject();
- try {
- String userId=request.getParameter("userId");
- String newPassword=request.getParameter("newPassword");
- user=new User();
- user.setUserId(Integer.parseInt(userId));
- user.setPassword(newPassword);
- userService.updateUser(user);
- result.put("success", "true");
- } catch (Exception e) {
- e.printStackTrace();
- result.put("success", "true");
- result.put("errorMsg", "对不起!密码修改失败");
- }
- WriterUtil.write(response, result.toString());
- }
-
-
- //安全退出
- @SuppressWarnings("unused")
- @RequestMapping("logout")
- private void logout(HttpServletRequest request,HttpServletResponse response) throws Exception{
- request.getSession().invalidate();
- response.sendRedirect("login.jsp");
- }
-
- }
- package dingzhen.controller;
-
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
-
- import dingzhen.entity.Room;
- import dingzhen.entity.Seat;
- import dingzhen.service.RoomService;
- import dingzhen.service.SeatService;
- import dingzhen.util.StringUtil;
- import dingzhen.util.WriterUtil;
- // 阅览室基本信息
-
- @RequestMapping("room")
- @Controller
- public class RoomController {
-
- private int page;
- private int rows;
- private Room room;
- @Autowired
- private RoomService<Room> roomService;
-
- @Autowired
- private SeatService<Seat> seatService;
-
- @RequestMapping("roomIndex")
- public String index(){
- return "readingroom/room";
- }
-
-
-
- @RequestMapping("roomList")
- public void roomList(HttpServletRequest request,HttpServletResponse response) {
- try {
- page = Integer.parseInt(request.getParameter("page"));
- rows = Integer.parseInt(request.getParameter("rows"));
- room = new Room();
- if(request.getParameter("typeid")!=null && request.getParameter("typeid").length() > 0){
- room.setTypeid(Integer.parseInt(request.getParameter("typeid")));
- }
- room.setPage((page-1)*rows);
- room.setRows(rows);
- List<Room> list = roomService.findRoom(room);
- int total = roomService.countRoom(room);
-
- JSONObject jsonObj = new JSONObject();//new一个JSON
- jsonObj.put("total",total );//total代表一共有多少数据
- jsonObj.put("rows", list);//row是代表显示的页的数据
- WriterUtil.write(response,jsonObj.toString()); //将上述Json输出,前台ajax接收
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-
-
-
- @RequestMapping("reserveRoom")
- public void reserveroom(HttpServletRequest request,HttpServletResponse response,Room room) {
- String id = request.getParameter("id");
- room.setTotal(room.getCol() * room.getRow()); //总座位数=列数 X 行数
- JSONObject result = new JSONObject();
- result.put("success", true);
- try {
- if(StringUtil.isNotEmpty(id)){
- room.setId(Integer.parseInt(id));
- roomService.updateRoom(room);
- } else {
- roomService.addRoom(room);
- /**int row=room.getRow();
- int cal=room.getCol();
- for(int rown=1; rown<=row; rown++) {
- for(int caln=1;caln<=cal;caln++) {
- Seat seat = new Seat();
- seat.setCol(caln);
- seat.setRow(rown);
- seat.setDate(id);
- seat.setStudentno("1");
- seatService.occupySeat(seat);
- }
- }**/
- int row=room.getRow();
- int cal=room.getCol();
- for(int rown=1; rown<=row; rown++) {
- for(int caln=1;caln<=cal;caln++) {
- try {
- Seat seat = new Seat();
- seat.setCol(caln);
- seat.setRow(rown);
- seat.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
- int roomid=roomService.getFinal();
- seat.setRoomid(roomid);
- seat.setTime("08点-12点");
- seat.setKeyword(new SimpleDateFormat("yyyy-MM-dd").format(new Date())+"-08点-12点-"+roomid+"-"+rown+"-"+caln);
- //2021-05-14-08点-12点-24-9-9
- seatService.insertSeat(seat);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }}
- }
- } catch (Exception e) {
- e.printStackTrace();
- result.put("errorMsg", "对不起!保存失败");
- }
- WriterUtil.write(response,result.toString());
- }
-
-
-
-
- @RequestMapping("deleteRoom")
- public void delete(HttpServletRequest request,HttpServletResponse response){
- JSONObject result=new JSONObject();
- try {
- String[] ids=request.getParameter("ids").split(",");
- for (String id : ids) {
- roomService.deleteRoom(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());
- }
-
-
-
- }
如果也想学习本系统,下面领取。关注并回复:171ssm
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。