使用springboot做的校园管理系统练习项目-前后端分离

57 阅读3分钟

今天给大家分享一个 我使用springboot框架开发的一个校园管理系统练习项目,代码就是需要多写多练,才能更好的掌握。

使用的技术:

java8

框架:Spring Boot 2.7

数据库:MySQL 8

前端:Vue 2

UI组件: Element UI

实现的系统功能有:

1、 课程管理

2、 教师管理

3、 学生管理

4、 公告管理

5、 管理员管理

6、 教学楼管理

7、 宿舍管理

8、 年级管理

9、班级管理

一共9个菜单,实际对于刚学习编程的小伙伴来说,功能还是比较多的,如果我们想快速的掌握一门编程语言,就是需要大量的项目来编写练习。就是有可能刚开始学习,写起来比较慢,但是只要我们坚持热爱,早晚都能学会的。

接下来给大家简单分享一些页面效果图:

首页:

image.png

课程列表:

image.png

学生管理:

image.png

课程计划:

image.png

页面功能还是挺多的,这里就不一一分享了,主要是分享我自己的学习心得和体会,如果你在学习java,希望对你有所帮助。 想更多的了解这个项目,可以获取一下完整的源码。(非开源项目) wwwoop.com/home/Index/…

源码里也有部分备注,如果你想学习,也是可以参考一下的尝试着自己写一个。

最后分享一些部分后端java代码:

image.png

package com.springboot.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springboot.base.entities.Student;
import com.springboot.base.exception.JsonlRuntimeException;
import com.springboot.base.mapper.StudentMapper;
import com.springboot.base.service.serviceInterface.IStudentService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 学生服务实现类
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Override
    public IPage<Student> pageList(Integer page, Integer pageSize, String search) {
        // 参数校验
        if (page == null || page < 1) {
            page = 1;
        }
        if (pageSize == null || pageSize < 1) {
            pageSize = 10;
        }
        
        // 创建分页对象
        Page<Student> pageParam = new Page<>(page, pageSize);
        
        // 调用Mapper进行多表查询
        return baseMapper.getStudentList(pageParam, search);
    }

    @Override
    public boolean add(Student student) {
        // 参数校验
        checkStudentParams(student);
        
        // 检查学号是否重复
        checkStudentNumberDuplicate(student.getStudentNumber(), null);
        
        // 保存学生信息
        return save(student);
    }

    @Override
    public boolean updateStudent(Student student) {
        // 参数校验
        if (student.getId() == null) {
            throw new JsonlRuntimeException("学生ID不能为空");
        }
        checkStudentParams(student);
        
        // 检查学号是否重复
        checkStudentNumberDuplicate(student.getStudentNumber(), student.getId());
        
        // 更新学生信息
        return updateById(student);
    }

    @Override
    public boolean deleteStudent(Integer id) {
        // 参数校验
        if (id == null) {
            throw new JsonlRuntimeException("学生ID不能为空");
        }
        
        // 检查学生是否存在
        Student student = getById(id);
        if (student == null) {
            throw new JsonlRuntimeException("学生不存在");
        }
        
        // 删除学生信息
        return removeById(id);
    }
    
    /**
     * 检查学生参数
     *
     * @param student 学生信息
     */
    private void checkStudentParams(Student student) {
        if (student == null) {
            throw new JsonlRuntimeException("学生信息不能为空");
        }
        if (StringUtils.isEmpty(student.getName())) {
            throw new JsonlRuntimeException("学生姓名不能为空");
        }
        if (StringUtils.isEmpty(student.getStudentNumber())) {
            throw new JsonlRuntimeException("学号不能为空");
        }
        if (student.getGender() == null) {
            throw new JsonlRuntimeException("性别不能为空");
        }
        if (student.getGradeId() == null) {
            throw new JsonlRuntimeException("年级不能为空");
        }
        if (StringUtils.isEmpty(student.getMajor())) {
            throw new JsonlRuntimeException("专业不能为空");
        }
        if (StringUtils.isEmpty(student.getIdCard())) {
            throw new JsonlRuntimeException("身份证号不能为空");
        }
        if (student.getClassId() == null) {
            throw new JsonlRuntimeException("班级不能为空");
        }
        if (StringUtils.isEmpty(student.getTeacherName())) {
            throw new JsonlRuntimeException("班主任姓名不能为空");
        }
        if (student.getIsGraduated() == null) {
            throw new JsonlRuntimeException("是否毕业不能为空");
        }
        if (student.getEnrollmentDate() == null) {
            throw new JsonlRuntimeException("入学日期不能为空");
        }
    }
    
    /**
     * 检查学号是否重复
     *
     * @param studentNumber 学号
     * @param id 学生ID(更新时使用)
     */
    private void checkStudentNumberDuplicate(String studentNumber, Integer id) {
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Student::getStudentNumber, studentNumber);
        if (id != null) {
            queryWrapper.ne(Student::getId, id);
        }
        long count = count(queryWrapper);
        if (count > 0) {
            throw new JsonlRuntimeException("学号已存在");
        }
    }
}