基于javaweb+mysql的+JPA图书馆座位占座预约管理系统(管理员、老师、学生)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
管理员:学生管理、教师管理、阅览室类型管理、阅览室管理(座位生成等)、学生信用积分管理、座位预约统计管理等。
学生:登录、修改个人信息、阅览室查看、选座信息查看、选座、取消选座等。
教师:登录、阅览室管理、学生信用管理:可根据学生表现进行扣分、奖励等,扣分达到设定的值则无法进行选座。
技术框架
JSP JavaScript SpringBoot SpringDataJPA FreeMarker MySQL
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
return null;
}
}
package com.demo.controller.admin;
import java.util.List;
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;
@Autowired
private RoleService roleService;
public Student findByID(Long id) {
/**
* 使用jpa自带的方法
* studentDao.getOne();当我查询一个不存在的id数据时,直接抛出异常,因为它返回的是一个引用,简单点说就是一个代理对象
* studentDao.findOne() 当我查询一个不存在的id数据时,返回的值是null.
* studentDao.findById(id) ; .findById(id).get()使用时,如果数据库中查询无符合条件的记录便会抛出异常
*/
Optional<Student> byId = studentDao.findById(id);
return byId.isPresent() ? byId.get() : null;
}
public List<Student> findAll() {
return studentDao.findAll();
}
/**
* 删除一个学生删除的时候需要先查出来相对的用户的id
* 先删除学生然后再删除相对应的用户
*
/**
* 生成验证码
* @return 验证码
*/
public String generatorVCode(){
int len = code.length;
Random ran = new Random();
StringBuffer sb = new StringBuffer();
for(int i = 0;i < vcodeLen;i++){
int index = ran.nextInt(len);
sb.append(code[index]);
}
return sb.toString();
}
/**
* 为验证码图片画一些干扰线
* @param g
*/
private void drawDisturbLine(Graphics g){
Random ran = new Random();
for(int i = 0;i < disturbline;i++){
int x1 = ran.nextInt(width);
int y1 = ran.nextInt(height);
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(clazz);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(clazz.getTeacher() == null || clazz.getTeacher().getTeacherSno() == null){
return Result.error(CodeMsg.ADMIN_ClAZZ_EMPTY );
}
//判断班级名是否存在
if(clazzService.isExistClaName(clazz.getClaname(), 0l)){
return Result.error(CodeMsg.ADMIN_ClAZZNAME_EXIST);
}
//到这说明一切符合条件,进行数据库新增
if(clazzService.save(clazz) == null){
return Result.error(CodeMsg.ADMIN_ClAZZ_ADD_ERROR);
}
operaterLogService.add("添加班级,班级名:" + clazz.getClaname());
return Result.success(true);
}
/**
* 班级编辑页面
* @param model
* @return
*/
@RequestMapping(value="/edit")
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("teachers",teacherService.findAll());
model.addAttribute("pageBean", seatService.findList(readingRoom, pageBean));
return "admin/seat/list";
}
/**
* 跳转设置座位可用页面
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/able", method = RequestMethod.GET)
public String ableSeat(Model model,@RequestParam(name="id",required=true)Long id) {
model.addAttribute("reading", readRoomService.findById(id));
List<Seat> seats = seatService.findByReadingRoomId(id);
model.addAttribute("seats", seats);
return "admin/seat/able";
}
@RequestMapping(value = "/able", method = RequestMethod.POST)
@ResponseBody
public Result<Boolean> ableSeat(@RequestParam(name = "id",required = true) Long id,
@RequestParam(name = "status",required = true) int status) {
public static final CodeMsg ADMIN_CLAZZ_TEACHER_EMPTY =new CodeMsg(-9005, "教师信息错误,请重新编辑!") ;
//学生扣分日志管理
public static final CodeMsg ADMIN_LOFINTEGRAL_CREDITS =new CodeMsg(-9005, "该学生没有那么多分数!") ;
}
package com.demo.common.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.Random;
/**
* 验证码生成器
*
* @author llq
*/
public class CpachaUtil {
return Result.error(CodeMsg.ADMIN_SEAT_EXIST);
}
List<Seat> seats = new ArrayList<>();
for (int x = 1; x <= readingRoom.getLie(); x++) {
for (int y = 1; y <= readingRoom.getRow(); y++) {
Seat seat = new Seat();
seat.setReadingRoom(readingRoom);
seat.setxAxis(x);
seat.setyAxis(y);
seats.add(seat);
}
}
if (seatService.saveAll(seats).isEmpty()) {
return Result.error(CodeMsg.ADMIN_SEAT_ADD_ERROR);
}
return Result.success(true);
}
import com.demo.common.util.MenuUtil;
import com.demo.common.util.ValidateEntityUtil;
/**
* 后台角色管理控制器
* @author Administrator
*
*/
@RequestMapping("/role")
@Controller
public class RoleController {
private Logger log = LoggerFactory.getLogger(RoleController.class);
@Autowired
private MenuService menuService;
@Autowired
private OperaterLogService operaterLogService;
@RequestMapping(value = "/choose", method = RequestMethod.GET)
public String choose(Model model,
@RequestParam(name = "date",required = true) Long date,
@RequestParam(name = "timeCode",required = true) int timeCode,
@RequestParam(name="id",required=true)Long id) {
if (Objects.isNull(date)) {
return "error/500";
}
if (Objects.isNull(timeCode)) {
return "error/500";
}
model.addAttribute("title", "选座管理");
model.addAttribute("date_time", DateUtil.millisecondToFormatDate(date));
model.addAttribute("timeCode", timeCode);
model.addAttribute("reading", readRoomService.findById(id));
List<Seat> seats = seatService.findByReadingRoomId(id);
List<Long> disableSeats = seatService.findDisableSeat(id, DateUtil.millisecondToDate(date), timeCode);
if (!disableSeats.isEmpty()) { //给已经占座的状态赋值2
seats = seats.stream().map(o -> {
return seatDao.findByReadingRoomId(readRoomId);
}
/**
* list存储座位
*
* @param seats
* @return
*/
public List<Seat> saveAll(List<Seat> seats) {
return seatDao.saveAll(seats);
}
/**
* 判断座位是否已生成
*
* @param id
* @return
*/
public boolean isExistReadingRoomId(Long id) {
}
//表示session未失效,进一步判断用户填写的验证码是否正确
if (!cpacha.equalsIgnoreCase(attribute.toString())) {
return Result.error(CodeMsg.CPACHA_ERROR);
}
//表示验证码正确,开始查询数据库,检验密码是否正确
User findByUsername = userService.findByUsername(user.getUsername());
//判断是否为空
if (findByUsername == null) {
return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
}
//表示用户存在,进一步对比密码是否正确
if (!findByUsername.getPassword().equals(user.getPassword())) {
return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
}
//表示密码正确,接下来判断用户状态是否可用
if (findByUsername.getStatus() == User.ADMIN_USER_STATUS_UNABLE) {
return Result.error(CodeMsg.ADMIN_USER_UNABLE);
}
//检查用户所属角色状态是否可用
/**
* 设置图片高度
* @param height
*/
public void setHeight(int height) {
this.height = height;
}
/**
* @return 干扰线条数
*/
public int getDisturbline() {
return disturbline;
}
/**
* 设置干扰线条数
* studentDao.getOne();当我查询一个不存在的id数据时,直接抛出异常,因为它返回的是一个引用,简单点说就是一个代理对象
* studentDao.findOne() 当我查询一个不存在的id数据时,返回的值是null.
* studentDao.findById(id) ; .findById(id).get()使用时,如果数据库中查询无符合条件的记录便会抛出异常
*/
Optional<Student> byId = studentDao.findById(id);
return byId.isPresent() ? byId.get() : null;
}
public List<Student> findAll() {
return studentDao.findAll();
}
/**
* 删除一个学生删除的时候需要先查出来相对的用户的id
* 先删除学生然后再删除相对应的用户
userService.delete(byID.getUser().getId());
}
/**
* 保存学生
* 用户需要固定一个学生的角色
*
* @param student
* @return
*/
@Transactional
public Student add(Student student) {
Role role = roleService.find(Student.STUDENT_ROLE_ENABLE);
String s = StringUtil.generateSn(Student.STUDENT_BIRTHDAY_ENABLE);
student.setStudentSno(s);
student.getUser().setPassword(s);
student.getUser().setUsername(s);
student.getUser().setRole(role);
User user = student.getUser();
* @param user
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(user.getRole() == null || user.getRole().getId() == null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
//判断用户名是否存在