通过编程解决下列问题:前后端代码实现实现基于web的学生管理系统的实例
时间: 2023-10-08 16:10:55 浏览: 51
由于基于web的学生管理系统的实现需要前后端联合实现,因此在下面提供一个基于Spring Boot、MyBatis、Vue等技术栈实现的学生管理系统前后端代码实现的示例,该示例包括以下功能:
1. 学生信息的增删改查操作。
2. 课程信息的增删改查操作。
3. 成绩信息的增删改查操作。
4. 学生和课程的关联操作。
5. 登录和退出系统的功能实现。
前端实现:
前端代码实现使用Vue、Element UI等技术,具体代码实现如下:
1. 学生信息管理页面的实现:
```
<template>
<div>
<h2>学生信息管理</h2>
<el-button type="primary" @click="addStudent">添加学生</el-button>
<el-table :data="students" style="width: 100%">
<el-table-column prop="id" label="学号"></el-table-column>
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="gender" label="性别"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="editStudent(scope.row)">编辑</el-button>
<el-button type="danger" size="mini" @click="deleteStudent(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog title="添加学生" :visible.sync="addStudentVisible">
<el-form :model="addStudentForm" label-width="80px">
<el-form-item label="学号">
<el-input v-model="addStudentForm.id"></el-input>
</el-form-item>
<el-form-item label="姓名">
<el-input v-model="addStudentForm.name"></el-input>
</el-form-item>
<el-form-item label="性别">
<el-radio-group v-model="addStudentForm.gender">
<el-radio label="男"></el-radio>
<el-radio label="女"></el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="年龄">
<el-input v-model="addStudentForm.age"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="addStudentVisible = false">取 消</el-button>
<el-button type="primary" @click="addStudentSubmit">确 定</el-button>
</div>
</el-dialog>
<el-dialog title="编辑学生" :visible.sync="editStudentVisible">
<el-form :model="editStudentForm" label-width="80px">
<el-form-item label="学号">
<el-input v-model="editStudentForm.id" disabled></el-input>
</el-form-item>
<el-form-item label="姓名">
<el-input v-model="editStudentForm.name"></el-input>
</el-form-item>
<el-form-item label="性别">
<el-radio-group v-model="editStudentForm.gender">
<el-radio label="男"></el-radio>
<el-radio label="女"></el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="年龄">
<el-input v-model="editStudentForm.age"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="editStudentVisible = false">取 消</el-button>
<el-button type="primary" @click="editStudentSubmit">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
students: [],
addStudentVisible: false,
addStudentForm: {
id: '',
name: '',
gender: '男',
age: ''
},
editStudentVisible: false,
editStudentForm: {
id: '',
name: '',
gender: '',
age: ''
}
};
},
methods: {
getStudents() {
axios.get('/api/students').then(response => {
this.students = response.data;
});
},
addStudent() {
this.addStudentVisible = true;
},
addStudentSubmit() {
axios.post('/api/students', this.addStudentForm).then(() => {
this.addStudentVisible = false;
this.addStudentForm = {
id: '',
name: '',
gender: '男',
age: ''
};
this.getStudents();
});
},
editStudent(student) {
this.editStudentVisible = true;
this.editStudentForm = {
id: student.id,
name: student.name,
gender: student.gender,
age: student.age
};
},
editStudentSubmit() {
axios.put(`/api/students/${this.editStudentForm.id}`, this.editStudentForm).then(() => {
this.editStudentVisible = false;
this.editStudentForm = {
id: '',
name: '',
gender: '',
age: ''
};
this.getStudents();
});
},
deleteStudent(student) {
axios.delete(`/api/students/${student.id}`).then(() => {
this.getStudents();
});
}
},
mounted() {
this.getStudents();
}
};
</script>
```
2. 课程信息管理页面的实现:
```
<template>
<div>
<h2>课程信息管理</h2>
<el-button type="primary" @click="addCourse">添加课程</el-button>
<el-table :data="courses" style="width: 100%">
<el-table-column prop="id" label="课程编号"></el-table-column>
<el-table-column prop="name" label="课程名称"></el-table-column>
<el-table-column prop="credit" label="学分"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="editCourse(scope.row)">编辑</el-button>
<el-button type="danger" size="mini" @click="deleteCourse(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog title="添加课程" :visible.sync="addCourseVisible">
<el-form :model="addCourseForm" label-width="80px">
<el-form-item label="课程编号">
<el-input v-model="addCourseForm.id"></el-input>
</el-form-item>
<el-form-item label="课程名称">
<el-input v-model="addCourseForm.name"></el-input>
</el-form-item>
<el-form-item label="学分">
<el-input v-model="addCourseForm.credit"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="addCourseVisible = false">取 消</el-button>
<el-button type="primary" @click="addCourseSubmit">确 定</el-button>
</div>
</el-dialog>
<el-dialog title="编辑课程" :visible.sync="editCourseVisible">
<el-form :model="editCourseForm" label-width="80px">
<el-form-item label="课程编号">
<el-input v-model="editCourseForm.id" disabled></el-input>
</el-form-item>
<el-form-item label="课程名称">
<el-input v-model="editCourseForm.name"></el-input>
</el-form-item>
<el-form-item label="学分">
<el-input v-model="editCourseForm.credit"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="editCourseVisible = false">取 消</el-button>
<el-button type="primary" @click="editCourseSubmit">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
courses: [],
addCourseVisible: false,
addCourseForm: {
id: '',
name: '',
credit: ''
},
editCourseVisible: false,
editCourseForm: {
id: '',
name: '',
credit: ''
}
};
},
methods: {
getCourses() {
axios.get('/api/courses').then(response => {
this.courses = response.data;
});
},
addCourse() {
this.addCourseVisible = true;
},
addCourseSubmit() {
axios.post('/api/courses', this.addCourseForm).then(() => {
this.addCourseVisible = false;
this.addCourseForm = {
id: '',
name: '',
credit: ''
};
this.getCourses();
});
},
editCourse(course) {
this.editCourseVisible = true;
this.editCourseForm = {
id: course.id,
name: course.name,
credit: course.credit
};
},
editCourseSubmit() {
axios.put(`/api/courses/${this.editCourseForm.id}`, this.editCourseForm).then(() => {
this.editCourseVisible = false;
this.editCourseForm = {
id: '',
name: '',
credit: ''
};
this.getCourses();
});
},
deleteCourse(course) {
axios.delete(`/api/courses/${course.id}`).then(() => {
this.getCourses();
});
}
},
mounted() {
this.getCourses();
}
};
</script
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)