java基于java的图书馆座位预约系统
时间: 2023-12-08 15:38:14 浏览: 131
基于Java的图书馆座位预约系统可以采用SSM框架(Spring、SpringMVC、MyBatis)进行开发。主要实现的功能包括用户管理、菜单管理、角色管理、权限管理、学生管理等。以下是该系统的主要功能模块:
1.用户管理模块:实现用户的添加、删除、修改和查询等功能。
```java
// 添加用户
@RequestMapping(value = "/addUser", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> addUser(User user) {
Map<String, Object> resultMap = new HashMap<>();
try {
userService.addUser(user);
resultMap.put("status", "success");
resultMap.put("msg", "添加用户成功!");
} catch (Exception e) {
resultMap.put("status", "error");
resultMap.put("msg", "添加用户失败!");
e.printStackTrace();
}
return resultMap;
}
// 删除用户
@RequestMapping(value = "/deleteUser", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> deleteUser(Integer id) {
Map<String, Object> resultMap = new HashMap<>();
try {
userService.deleteUser(id);
resultMap.put("status", "success");
resultMap.put("msg", "删除用户成功!");
} catch (Exception e) {
resultMap.put("status", "error");
resultMap.put("msg", "删除用户失败!");
e.printStackTrace();
}
return resultMap;
}
// 修改用户
@RequestMapping(value = "/updateUser", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateUser(User user) {
Map<String, Object> resultMap = new HashMap<>();
try {
userService.updateUser(user);
resultMap.put("status", "success");
resultMap.put("msg", "修改用户成功!");
} catch (Exception e) {
resultMap.put("status", "error");
resultMap.put("msg", "修改用户失败!");
e.printStackTrace();
}
return resultMap;
}
// 查询用户
@RequestMapping(value = "/getUserList", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getUserList(Integer page, Integer rows, String username) {
Map<String, Object> resultMap = new HashMap<>();
try {
List<User> userList = userService.getUserList(page, rows, username);
Long total = userService.getTotal(username);
resultMap.put("rows", userList);
resultMap.put("total", total);
} catch (Exception e) {
e.printStackTrace();
}
return resultMap;
}
```
2.座位管理模块:实现座位的预约、取消预约、查询座位状态等功能。
```java
// 预约座位
@RequestMapping(value = "/reserveSeat", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> reserveSeat(Integer seatId, Integer userId) {
Map<String, Object> resultMap = new HashMap<>();
try {
Seat seat = seatService.getSeatById(seatId);
if (seat.getStatus() == 0) {
seat.setStatus(1);
seat.setUserId(userId);
seatService.updateSeat(seat);
resultMap.put("status", "success");
resultMap.put("msg", "预约座位成功!");
} else {
resultMap.put("status", "error");
resultMap.put("msg", "该座位已被预约!");
}
} catch (Exception e) {
resultMap.put("status", "error");
resultMap.put("msg", "预约座位失败!");
e.printStackTrace();
}
return resultMap;
}
// 取消预约
@RequestMapping(value = "/cancelReservation", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> cancelReservation(Integer seatId) {
Map<String, Object> resultMap = new HashMap<>();
try {
Seat seat = seatService.getSeatById(seatId);
seat.setStatus(0);
seat.setUserId(null);
seatService.updateSeat(seat);
resultMap.put("status", "success");
resultMap.put("msg", "取消预约成功!");
} catch (Exception e) {
resultMap.put("status", "error");
resultMap.put("msg", "取消预约失败!");
e.printStackTrace();
}
return resultMap;
}
// 查询座位状态
@RequestMapping(value = "/getSeatStatus", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getSeatStatus(Integer seatId) {
Map<String, Object> resultMap = new HashMap<>();
try {
Seat seat = seatService.getSeatById(seatId);
if (seat.getStatus() == 0) {
resultMap.put("status", "success");
resultMap.put("msg", "该座位未被预约!");
} else {
resultMap.put("status", "error");
resultMap.put("msg", "该座位已被预约!");
}
} catch (Exception e) {
resultMap.put("status", "error");
resultMap.put("msg", "查询座位状态失败!");
e.printStackTrace();
}
return resultMap;
}
```
阅读全文