Student information management system based on Springboot

table of Contents

1. System analysis

2. System design

2.1, front-end module

2.2, back-end module

2.3, database module

Three, system implementation

3.1, front-end implementation

3.2, back-end implementation


The front-end uses Vue.js+Element.UI for development, and the back-end uses Springboot+MyBatis. MySQL is used for the database. If you need source code, you can add Q: 914259961

 

 

2.1 , front-end module

The login page consists of a form with two input boxes, account number and password. After the input is successful, it will jump to the information management page, otherwise the reason for the login failure will be prompted.

Then there are four information management pages, namely student information management, class information management, teacher information management, and course information management.

The student information management page can manage student information, and can query by student's name and distinguish by class.

The class information management page can manage class information, and can inquire by profession. Double-click a class to jump to the page of all students in that class.

The teacher information management page can manage the teacher's information, and you can query by the teacher's name.

The course information management page can manage course information, which can be inquired by course name, and distinguished by course opening semester, class, and instructor.

Double-clicking a semester cell will jump to all courses in the semester; double-clicking a class will jump to all courses of that class; double-clicking a teacher will jump to all courses of that teacher. Can be selected at the same time.

 

 

2.2 , back-end module

The presentation layer is used to receive data and return data. Using the RestFul interface style, the functions of the interface are distinguished by the type of the interface.

The service layer is where the specific business is realized. Process the data in the presentation layer, call the interface of the persistence layer, add, delete, check and modify the data, and perform related cascading operations.

Because the database uses logical foreign keys, it is necessary to perform related operations on the association between tables in the service layer.

The persistence layer is where the data is accessed. The MyBatis framework is used to encapsulate the database access, and the object-relational mapping is completed by associating the entities related to the database table, which simplifies the operation of the database.

 

Figure 1 Class diagram

 

 

2.3 , database module

The database is MySQL, and the database is named student_db. There are six tables in total, namely student table, teacher table, class table, course table, account table and history table of flyway automatically build database.

The foreign key of the class table is added to the student table, and then the foreign key of the class table and the foreign key of the teacher table are added to the course table. Through these foreign key associations, the completed associations between entities in the back-end module,

Makes its use in the back-end more convenient.

 

Figure 2 Database table structure

 

 

3.1 , front-end implementation

1. Login page

There is a form in the middle of the page. The two input boxes add form validation and cannot be empty. Then the two buttons are one for login and the other is for resetting the input of the input box. The form is processed transparently.

 

Figure 3 Login page

 

 

2. Student management page

 

Figure 4 Student Management Page

 

Figure 5 Adding a student

 

Figure 6 Editing students

 

3. Class management page

 

Figure 7 Class management page

 

Figure 8 Adding a class

 

Figure 9 Editing the class

 

4. Teacher management page

 

Figure 10 Teacher management page

 

Figure 11 Add a teacher

 

Figure 12 Edit teacher

 

5. Course management page

 

Figure 13 Course Management Page

 

Figure 14 Add a course

 

Figure 15 Editing the course

 

3.2 , back-end implementation

1. Program entry

package com.management.app;


import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan("com.management.app.core.mapper")
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

 

2. Performance layer (student information)

package com.management.app.api;


import com.management.app.core.model.entity.Student;
import com.management.app.core.service.IStudentService;
import com.management.app.support.Rest;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/students")
public class StudentApi {

    private final IStudentService service;

    public StudentApi(IStudentService service) {
        this.service = service;
    }

    @GetMapping
    public Rest<?> findPaging(@RequestParam(required = false) Integer pageNumber,
                              @RequestParam(required = false) Integer pageSize,
                              @RequestParam(required = false) String name,
                              @RequestParam(required = false) Integer teamId) {
        return Rest.ok(service.findPaging(pageNumber, pageSize, teamId, name));
    }

    @GetMapping("/{id}")
    public Rest<Student> findById(@PathVariable Integer id) {
        return Rest.ok(service.findById(id));
    }

    @PostMapping
    public Rest<?> create(@RequestBody Student student) {
        service.create(student);
        return Rest.ok();
    }

    @PutMapping("/{id}")
    public Rest<?> update(@PathVariable Integer id, @RequestBody Student student) {
        service.update(id, student);
         return Rest.ok();
    }

    @DeleteMapping("/{id}")
    public Rest<?> delete(@PathVariable Integer id) {
        service.delete(id);
        return Rest.ok();
    }
}

 

3. Service layer (student information)

package com.management.app.core.service.impl;


import com.management.app.core.model.entity.Student;
import com.management.app.core.mapper.StudentMapper;
import com.management.app.core.model.vo.StudentVO;
import com.management.app.core.service.IStudentService;
import com.management.app.support.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.management.app.infrastructure.consts.AppConst.DEFAULT_NUMBER;
import static com.management.app.infrastructure.consts.AppConst.DEFAULT_SIZE;

@Service
public class StudentServiceImpl implements IStudentService {

    private final StudentMapper mapper;

    public StudentServiceImpl(StudentMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public Student findById(Integer id) {
        return mapper.selectStudent(id);
    }

    @Override
    public PageInfo findPaging(Integer pageNumber, Integer pageSize,Integer teamId, String name) {
        Integer totalCount = mapper.selectStudentCount(teamId, name);
        if (pageNumber == null || pageSize == null) {
            //
默认返回分页8
            return new PageInfo(DEFAULT_NUMBER,
                    DEFAULT_SIZE,
                    totalCount,
                    mapper.selectStudentPage(DEFAULT_NUMBER, DEFAULT_SIZE, teamId, name));
        }
        List<Student> content = mapper.selectStudentPage(pageNumber * pageSize, pageSize, teamId, name);
        List<StudentVO> vos = StudentVO.mapFrom(content);
        return new PageInfo(pageNumber, pageSize, totalCount, vos);
    }

    private void setBaseProperties(Student entity, Student model) {
        entity.setProperties(model);
    }

    @Override
    public void create(Student model) {
        Student entity = new Student();
        setBaseProperties(entity, model);
        mapper.insertStudent(entity);
    }

    @Override
    public void update(Integer id, Student model) {
        Student entity = findById(id);
        setBaseProperties(entity, model);
        mapper.updateStudent(entity);
    }

    @Override
    public void delete(Integer id) {
        mapper.deleteStudent(id);
    }

}

 

4. Persistence layer (student information)

package com.management.app.core.mapper;


import com.management.app.core.model.entity.Student;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentMapper {

    Student selectStudent(Integer id);

    Integer selectStudentCount(Integer teamId, String name);

    List<Student> selectStudentPage(Integer startIndex, Integer pageSize, Integer teamId, String name);

    void insertStudent(Student student);

    void updateStudent(Student student);

    void deleteStudent(Integer id);

    void deleteStudents(Integer teamId);
}

Mapper.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.management.app.core.mapper.StudentMapper">
    <resultMap id="studentMap" type="Student">
        <result column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="student_number" property="studentNumber"/>
        <result column="birth_date" property="birthDate" />
        <result column="gender" property="gender" />
        <result column="national" property="national" />
        <result column="phone_number" property="phoneNumber" />
        <result column="native_place" property="nativePlace"/>
        <result column="team_id" property="teamId"/>
<!--        <association property="team" column="team_id"-->
<!--            resultMap="teamMap" columnPrefix="t_"/>-->
    </resultMap>

    <!--
使用嵌套查询,可避免n+1问题-->
    <select id="selectStudent" resultMap="studentMap">
        select
            id,
            name,
            student_number,
            birth_date,
            gender,
            national,
            phone_number,
            team_id,
            native_place
        from student
        where id = #{id};
    </select>

<!--   
查询总个数 (只有一个参数时用_parameter 使用CONCAT拼接%通配符 -->
    <select id="selectStudentCount" resultType="java.lang.Integer">
        select count(*)
        from student
        <if test="teamId!=null">where team_id = #{teamId}
            <if test="name!=null">and name like CONCAT('%',#{name},'%')</if>
        </if>
        <if test="teamId==null">
            <if test="name!=null">where name like CONCAT('%',#{name},'%')</if>
        </if>
    </select>

    <select id="selectStudentPage" resultMap="studentMap">
        select *
        from student
        <if test="teamId!=null">where team_id = #{teamId}
            <if test="name!=null">and name like CONCAT('%',#{name},'%')</if>
        </if>
        <if test="teamId==null">
            <if test="name!=null">where name like CONCAT('%',#{name},'%')</if>
        </if>
        order by CONVERT(student_number,SIGNED) asc
        limit  #{startIndex},#{pageSize}
    </select>

    <insert id="insertStudent" parameterType="com.management.app.core.model.entity.Student" keyProperty="id">
        insert into
        student(name, student_number, birth_date, gender, national, phone_number, team_id, native_place)
        values(#{name}, #{studentNumber}, #{birthDate}, #{gender}, #{national}, #{phoneNumber}, #{teamId}, #{nativePlace});
    </insert>

    <update id="updateStudent" parameterType="com.management.app.core.model.entity.Student">
        UPDATE student
        <set>
            <if test="name != null">name=#{name},</if>
            <if test="studentNumber!=null">student_number=#{studentNumber},</if>
            <if test="birthDate!=null">birth_date=#{birthDate},</if>
            <if test="gender!=null">gender=#{gender},</if>
            <if test="national!=null">national=#{national},</if>
            <if test="phoneNumber!=null">phone_number=#{phoneNumber},</if>
            <if test="teamId!=null">team_id=#{teamId},</if>
            <if test="nativePlace!=null">native_place=#{nativePlace},</if>
        </set>
        WHERE
        id=#{id};
    </update>

    <delete id="deleteStudent" parameterType="int" >
        delete from
        student
        where
        id=#{id}
    </delete>

    <delete id="deleteStudents" parameterType="int" >
        delete from
        student
        where
        team_id=#{teamId}
    </delete>

</mapper>

 

 

Guess you like

Origin blog.csdn.net/qq_43621091/article/details/113094570