基于javaweb+mysql的springboot课程自动排课系统(java+springboot+html+layui+thymeleaf+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot课程自动排课系统(java+springboot+html+layui+thymeleaf+mysql)
项目介绍
课程自动排课系统
主要功能包括: 首页:查看分课、查看课表、查看空教室; 班级设置:添加班级、分配课程、编辑、删除课程; 教室设置:添加教室、编辑、删除; 课程设置:添加课程、编辑、删除; 教师设置:添加教师、编辑、删除; 排课管理:调整排课、删除排课;
用户管理:添加用户、编辑、删除;
环境需要
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.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 6.数据库:MySql 8.0版本;
技术栈
-
后端:Springboot
-
前端:html+layui+thymeleaf
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 将项目中application.properties配置文件中的数据库配置改为自己的配置 3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行; 4. 运行项目,输入http://localhost:8080/login.html 登录
@RequestMapping("findBy")
public ServerResponse<List<CourseTable>> find(String className, String teacherName,Integer week) {
if ((className==null||"".equals(className)&&(teacherName==null||"".equals(teacherName)))){
return ServerResponse.createByErrorMessage("请输入正确参数");
}
if (week==null||week==0){
return ServerResponse.createByErrorMessage("请选择周数");
}
return iCourseTableService.findBy(className,teacherName,week);
}
@RequestMapping("add")
public ServerResponse<String> add(CourseTable courseTable) {
return iCourseTableService.add(courseTable);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iCourseTableService.del(id);
}
@RequestMapping("update")
public ServerResponse<String> update(CourseTable courseTable) {
return iCourseTableService.update(courseTable);
}
@RequestMapping("find")
public ServerResponse<CourseTable> find(Integer id) {
return iCourseTableService.find(id);
}
@RequestMapping("findAll")
public ServerResponse<PageInfo<CourseTable>> findAll(Integer pageNum, Integer pageSize) {
return iCourseTableService.findAll(pageNum, pageSize);
}
@RequestMapping("findAllBy")
public ServerResponse<PageInfo<CourseTable>> findAllBy(HttpServletRequest request,Integer pageNum, Integer pageSize, Integer week,
String courseName, String className, String teacherName,
String roomName) {
System.out.println(request.getRequestURI());
System.out.println(request.getServletPath());
return iCourseTableService.findAllBy(pageNum, pageSize,week,courseName,className,teacherName,roomName);
}
/**
* var day = data.day;
/**
*
*/
@RestController
@RequestMapping("/arrange/")
public class ArrangeController {
@Autowired
private IArrangeService iArrangeService;
@RequestMapping("add")
public ServerResponse<String> add(Arrange arrange) {
return iArrangeService.add(arrange);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iArrangeService.del(id);
}
@RequestMapping("update")
public ServerResponse<String> update(Arrange arrange) {
return iArrangeService.update(arrange);
}
@RequestMapping("find")
public ServerResponse<Arrange> find(Integer id) {
return iArrangeService.find(id);
}
@RequestMapping("findAll")
public ServerResponse<PageInfo<Arrange>> findAll(Integer pageNum, Integer pageSize) {
/**
* 登录
*
* @param username
* @param password
* @param role
* @param session
* @return
*/
@RequestMapping("login")
public ServerResponse<User> login(String username, String password, String role, HttpSession session, HttpServletRequest request) {
ServerResponse<User> login = iUserService.login(username, password, role);
if (login.isSuccess()) {
session.setAttribute("user", login.getData());
currentLoginUser = login.getData();
System.out.println(session.getId());
}
return login;
}
/**
* 根据id删除用户
*
* @param id
* @return
*/
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
if (currentLoginUser.getRole().equals(Constant.NOT_ADMIN)) {
return ServerResponse.createByErrorMessage("权限不足!");
}
return iUserService.del(id);
}
/**
* 查找全部用户
*
* @param session
* @return
*/
@RequestMapping("findAll")
public LayerResponse<List<User>> findAll(HttpSession session, Integer pageNum, Integer pageSize, HttpServletRequest request) {
User user = (User) session.getAttribute("user");
ServerResponse<PageInfo<User>> all = iUserService.findAll(currentLoginUser.getRole(), pageNum, pageSize);
return ToLayerUtil.toLayer(all);
pageInfo.setTotal(byWeek.size());
return ServerResponse.createBySuccess(pageInfo);
}
}
/**
*
*/
@RestController
@RequestMapping("/course/")
public class CourseController {
@Autowired
private ICourseService iCourseService;
@RequestMapping("add")
public ServerResponse<String> add(String courseName, Integer courseTime,Integer sord) {
return iCourseService.add(courseName, courseTime,sord);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iCourseService.del(id);
}
@RequestMapping("update")
public ServerResponse<String> update(Integer id, String courseName, Integer courseTime,Integer sord) {
return iCourseService.update(id, courseName, courseTime,sord);
}
@RequestMapping("find")
public ServerResponse<Course> find(Integer id) {
return iCourseService.find(id);
}
@RequestMapping("findAll")
public ServerResponse<PageInfo<Course>> findAll(Integer pageNum, Integer pageSize) {
return iCourseService.findAll(pageNum, pageSize);
}
*
* @param username
* @param password
* @param role
* @param session
* @return
*/
@RequestMapping("login")
public ServerResponse<User> login(String username, String password, String role, HttpSession session, HttpServletRequest request) {
ServerResponse<User> login = iUserService.login(username, password, role);
if (login.isSuccess()) {
session.setAttribute("user", login.getData());
currentLoginUser = login.getData();
System.out.println(session.getId());
}
return login;
}
/**
* 根据id删除用户
*
* @param id
* @return
*/
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
if (currentLoginUser.getRole().equals(Constant.NOT_ADMIN)) {
return ServerResponse.createByErrorMessage("权限不足!");
}
return iUserService.del(id);
}
/**
* 查找全部用户
*
* @param session
* @return
*/
@RequestMapping("findAll")
public LayerResponse<List<User>> findAll(HttpSession session, Integer pageNum, Integer pageSize, HttpServletRequest request) {
User user = (User) session.getAttribute("user");
ServerResponse<PageInfo<User>> all = iUserService.findAll(currentLoginUser.getRole(), pageNum, pageSize);
return ToLayerUtil.toLayer(all);
}
/**
/**
*
*/
@RestController
@RequestMapping("/classroom/")
public class ClassroomController {
@Autowired
private IClassroomService iClassroomService;
@RequestMapping("add")
public ServerResponse<String> add(String roomName, Integer roomSpace, Integer roomLayer) {
return iClassroomService.add(roomName, roomSpace, roomLayer);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iClassroomService.del(id);
}
@RequestMapping("update")
public ServerResponse<String> update(Integer id, String roomName, Integer roomSpace, Integer roomLayer) {
return iClassroomService.update(id, roomName, roomSpace, roomLayer);
}
@RequestMapping("find")
public ServerResponse<Classroom> find(Integer id) {
return iClassroomService.find(id);
}
/**
*
*/
@RestController
@RequestMapping("/classroom/")
public class ClassroomController {
@Autowired
private IClassroomService iClassroomService;
@RequestMapping("add")
public ServerResponse<String> add(String roomName, Integer roomSpace, Integer roomLayer) {
return iClassroomService.add(roomName, roomSpace, roomLayer);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iClassroomService.del(id);
}
@RequestMapping("update")
public ServerResponse<String> update(Integer id, String roomName, Integer roomSpace, Integer roomLayer) {
return iClassroomService.update(id, roomName, roomSpace, roomLayer);
}
@RequestMapping("find")
public ServerResponse<Classroom> find(Integer id) {
return iClassroomService.find(id);
}
@RequestMapping("findAll")
public ServerResponse<PageInfo<Classroom>> findAll(Integer pageNum, Integer pageSize) {
return iClassroomService.findAll(pageNum, pageSize);
}
@RequestMapping("findByWeek")
public ServerResponse<PageInfo<ClassroomFree>> findByWeek(Integer pageNum, Integer pageSize, Integer week,String roomName,String day) {
List<ClassroomFree> byWeek = iClassroomService.findByWeek(week,roomName);
List<ClassroomFree> collect;
/**
* 查找全部用户
*
* @param session
* @return
*/
@RequestMapping("findAll")
public LayerResponse<List<User>> findAll(HttpSession session, Integer pageNum, Integer pageSize, HttpServletRequest request) {
User user = (User) session.getAttribute("user");
ServerResponse<PageInfo<User>> all = iUserService.findAll(currentLoginUser.getRole(), pageNum, pageSize);
return ToLayerUtil.toLayer(all);
}
/**
* 根据id查找用户
*
* @param id
* @return
*/
@RequestMapping("find")
public ServerResponse<User> find(Integer id) {
return iUserService.findById(id);
}
/**
* 更新用户信息
*
* @param id
* @param username
* @param password
* @return
*/
@RequestMapping("update")
public ServerResponse<String> update(Integer id, String username, String password, String role) {
if (currentLoginUser.getRole().equals(Constant.NOT_ADMIN)) {
return ServerResponse.createByErrorMessage("权限不足!");
}
return iUserService.update(id, username, password, role);
}
}
/**
*
*/
@RestController
@RequestMapping("/arrange/")
public class ArrangeController {
@Autowired
private IArrangeService iArrangeService;
@RequestMapping("add")
public ServerResponse<String> add(Arrange arrange) {
return iArrangeService.add(arrange);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iArrangeService.del(id);
}
@RequestMapping("update")
public ServerResponse<String> update(Arrange arrange) {
return iArrangeService.update(arrange);
}
@RequestMapping("find")
public ServerResponse<Arrange> find(Integer id) {
return iArrangeService.find(id);
}
@RequestMapping("findAll")
public ServerResponse<PageInfo<Arrange>> findAll(Integer pageNum, Integer pageSize) {
return iArrangeService.findAll(pageNum, pageSize);
}
}
return iCourseService.update(id, courseName, courseTime,sord);
}
@RequestMapping("find")
public ServerResponse<Course> find(Integer id) {
return iCourseService.find(id);
}
@RequestMapping("findAll")
public ServerResponse<PageInfo<Course>> findAll(Integer pageNum, Integer pageSize) {
return iCourseService.findAll(pageNum, pageSize);
}
@RequestMapping("findAllByName")
public ServerResponse<PageInfo<Course>> findAllByName(Integer pageNum, Integer pageSize,String courseName) {
return iCourseService.findAllByName(pageNum, pageSize,courseName);
}
}
/**
*
*/
@RestController
@RequestMapping("/classes/")
public class ClassesController {
@Autowired
private IClassesService iClassesService;
@RequestMapping("add")
public ServerResponse<String> add(String className, String classNum,Integer limit) {
return iClassesService.add(className, classNum,limit);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iClassesService.del(id);
}
/**
* 根据id查找用户
*
* @param id
* @return
*/
@RequestMapping("find")
public ServerResponse<User> find(Integer id) {
return iUserService.findById(id);
}
/**
* 更新用户信息
*
* @param id
* @param username
* @param password
* @return
*/
@RequestMapping("update")
public ServerResponse<String> update(Integer id, String username, String password, String role) {
if (currentLoginUser.getRole().equals(Constant.NOT_ADMIN)) {
return ServerResponse.createByErrorMessage("权限不足!");
}
return iUserService.update(id, username, password, role);
}
}
/**
*
*/
@RestController
@RequestMapping("/coursetable/")
public class CourseTableController {
/**
*
*/
@Slf4j
public class AuthorityInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 如果不是映射到方法直接通过
if (!(handler instanceof HandlerMethod)) {
return true;
}
// ①:START 方法注解级拦截器
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
// 判断接口是否需要登录
LoginRequired methodAnnotation = method.getAnnotation(LoginRequired.class);
// 有 @LoginRequired 注解,需要认证
if (methodAnnotation != null) {
String value = methodAnnotation.value();
// 这写你拦截需要干的事儿,比如取缓存,SESSION,权限判断等
HttpSession session = request.getSession();
Object user = session.getAttribute("user");
if (user == null) {
ServerResponse<String> errorMessage = ServerResponse.createByErrorMessage("没有登录");
String jsonObjectStr = JSONObject.toJSONString(errorMessage);
returnJson(request, response, jsonObjectStr);
return false;
}
return true;
}
return true;
}
private void returnJson(HttpServletRequest request, HttpServletResponse response, String json) throws Exception {
String origin = request.getHeader("Origin");
response.setHeader("Access-Control-Allow-Origin", origin);
response.setHeader("Access-Control-Allow-Methods", "*");
response.setHeader("Access-Control-Allow-Headers", "Origin,Content-Type,Accept,token,X-Requested-With");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}
}
/**
*
*/
@RestController
@RequestMapping("/teacher/")
public class TeacherController {
@Autowired
private ITeacherService iTeacherService;
@RequestMapping("add")
public ServerResponse<String> add(String name, String phone,Integer countLimit) {
return iTeacherService.add(name, phone,countLimit);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iTeacherService.del(id);
}
@RequestMapping("update")
public ServerResponse<String> update(Integer id, String name, String phone,Integer countLimit) {
return iTeacherService.update(id, name, phone,countLimit);
}
@RequestMapping("find")
public ServerResponse<Teacher> find(Integer id) {
return iTeacherService.find(id);
}
return iClassroomService.find(id);
}
@RequestMapping("findAll")
public ServerResponse<PageInfo<Classroom>> findAll(Integer pageNum, Integer pageSize) {
return iClassroomService.findAll(pageNum, pageSize);
}
@RequestMapping("findByWeek")
public ServerResponse<PageInfo<ClassroomFree>> findByWeek(Integer pageNum, Integer pageSize, Integer week,String roomName,String day) {
List<ClassroomFree> byWeek = iClassroomService.findByWeek(week,roomName);
List<ClassroomFree> collect;
if (day!=null&&!"".equals(day)){
collect= byWeek.stream().filter(s->s.getDay().equals(day)).skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
}else {
collect= byWeek.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
}
PageInfo<ClassroomFree> pageInfo = new PageInfo<>(collect);
pageInfo.setTotal(byWeek.size());
return ServerResponse.createBySuccess(pageInfo);
}
}
/**
*
*/
@RestController
@RequestMapping("/course/")
public class CourseController {
@Autowired
private ICourseService iCourseService;
@RequestMapping("add")
public ServerResponse<String> add(String courseName, Integer courseTime,Integer sord) {
return iCourseService.add(courseName, courseTime,sord);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iCourseService.del(id);
log.error("response error", e);
}
}
}
/**
*
*/
@RestController
@RequestMapping("/classroom/")
public class ClassroomController {
@Autowired
private IClassroomService iClassroomService;
@RequestMapping("add")
public ServerResponse<String> add(String roomName, Integer roomSpace, Integer roomLayer) {
return iClassroomService.add(roomName, roomSpace, roomLayer);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iClassroomService.del(id);
}
@RequestMapping("update")
public ServerResponse<String> update(Integer id, String roomName, Integer roomSpace, Integer roomLayer) {
return iClassroomService.update(id, roomName, roomSpace, roomLayer);
private void returnJson(HttpServletRequest request, HttpServletResponse response, String json) throws Exception {
String origin = request.getHeader("Origin");
response.setHeader("Access-Control-Allow-Origin", origin);
response.setHeader("Access-Control-Allow-Methods", "*");
response.setHeader("Access-Control-Allow-Headers", "Origin,Content-Type,Accept,token,X-Requested-With");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter writer = response.getWriter()) {
writer.print(json);
} catch (IOException e) {
log.error("response error", e);
}
}
}
/**
*
*/
@RestController
@RequestMapping("/classroom/")
public class ClassroomController {
@Autowired
private IClassroomService iClassroomService;
@RequestMapping("add")
public ServerResponse<String> add(String roomName, Integer roomSpace, Integer roomLayer) {
return iClassroomService.add(roomName, roomSpace, roomLayer);
}
@RequestMapping("del")
public ServerResponse<String> del(Integer id) {
return iClassroomService.del(id);
}
@RequestMapping("findAll")
public ServerResponse<PageInfo<CourseTable>> findAll(Integer pageNum, Integer pageSize) {
return iCourseTableService.findAll(pageNum, pageSize);
}
@RequestMapping("findAllBy")
public ServerResponse<PageInfo<CourseTable>> findAllBy(HttpServletRequest request,Integer pageNum, Integer pageSize, Integer week,
String courseName, String className, String teacherName,
String roomName) {
System.out.println(request.getRequestURI());
System.out.println(request.getServletPath());
return iCourseTableService.findAllBy(pageNum, pageSize,week,courseName,className,teacherName,roomName);
}
/**
* var day = data.day;
* var week = data.week;
* var number = data.number;
* var classroomId = data.classroomId;
* var classroomName = data.classroomName;
* console.log(day+" "+week+" "+number+" "+classroomId+" "+classroomName)
* console.log(courseTableId)
*/
@RequestMapping("adjust")
public ServerResponse<String> adjust(Integer courseTableId,String day,Integer week,Integer number,String classroomName,Integer classroomId){
return iCourseTableService.adjust(courseTableId,classroomId,week,day,number,classroomName);
}
}
/**