学生管理系统springboot+vue

学生管理系统springboot+vue

要求

实现用户登录,对用户分为三类,老师,班长,学生,老师可以录入平时成绩,期末成绩,还有权重,需要根据这个计算出最终成绩,学生可以查询自己的成绩,班长除了查询自己的成绩,还可以查询班上其他人的成绩,并按成绩从高到低

项目目录

前端:
在这里插入图片描述
在这里插入图片描述
后端:
在这里插入图片描述

源码

前端

grade_input.vue

<template>
  <div style="width:62%;margin: auto;">
    <el-table :data="grades" border style="width: 100%">
      <el-table-column fixed prop="id" label="序号" width="50">
      </el-table-column>
      <el-table-column prop="stuId" label="学生id" width="100">
      </el-table-column>
      <el-table-column prop="sName" label="姓名" width="100">
      </el-table-column>
      <el-table-column prop="classId" label="所属班级" width="100">
      </el-table-column>
      <el-table-column prop="courseName" label="课程名称" width="130">
      </el-table-column>
      <el-table-column prop="regular_score" label="平时成绩" width="100">
      </el-table-column>
      <el-table-column prop="exam_score" label="期末成绩" width="100">
      </el-table-column>
      <el-table-column prop="final_score" label="最终成绩" width="100">
      </el-table-column>
      <el-table-column prop="weight" label="平时成绩占比" width="100">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">录入成绩</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--  添加对话框 -->
    <el-dialog title="录入成绩" :visible.sync="dialogVisible" width="30%">
      <el-form :model="gradeForm">
        <el-form-item label="平时成绩">
          <el-input v-model="gradeForm.regular_score" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="考试成绩">
          <el-input v-model="gradeForm.exam_score" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="权重">
          <el-input v-model="gradeForm.weight" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submitGrade">提交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { GetAllGradesByteacherId } from '@/api/gradeService';
import axios from 'axios';
/* import { get } from 'core-js/core/dict'; */
/* import { GetAllGrades } from '@/api/gradeService'; */

export default {
  data() {
    return {
      grades:[],
      userId:null,
      dialogVisible: false, // 添加对话框可见性状态
      gradeForm: { // 添加表单数据模型
        studentId: null,
        courseId: null,
        gradeId:null,
        regular_score: '',
        exam_score: '',
        weight: ''
      },
      message: ""
    };
  },
  created(){
    this.userId = this.$route.query.userId;
    if (!this.userId) {
    // 处理没有 userId 的情况
    this.message = '错误:缺少用户ID';
    console.log('错误:缺少用户ID:'); 
  } else {
    this.fetchGrade();
  }
  },
  methods: {
    fetchGrade() {
      console.log('Fetching grades for user ID:', this.userId); // 检查是否执行
      if(this.userId)
    {
      /* this.userId=this.$route.params.userId; */
     /*  GetAllGrades() */
      GetAllGradesByteacherId(this.userId)
      .then(Response => {
        this.grades=Response.data;
      })
      .catch(error => {
          console.error('Error fetching grades:', error); // 处理错误
        });
    }
     
    },
    handleClick(row){
      this.gradeForm = { ...row }; // 初始化表单数据为当前行数据
      this.dialogVisible = true; // 显示对话框
    },
    submitGrade() {
      console.log("Submitting grade:", this.gradeForm.id);
      console.log("Submitting grade:", this.gradeForm.regular_score);
      axios.put(`http://localhost:8081/update/${this.gradeForm.id}`,
      {regular_score: this.gradeForm.regular_score,
      exam_score: this.gradeForm.exam_score,
      weight: this.gradeForm.weight
    })
    .then(()=> {
      this.message = "成绩录入成功";
      this.dialogVisible = false; // 关闭对话框
      this.fetchGrade(); // 刷新成绩列表
      this.clearForm(); // 清空表单
    })
    .catch(error => {
      console.error("Error updating grade:", error);
      this.message = "成绩录入失败"; // 显示错误信息
    });
    },
    clearForm() {
      this.grade = {
        studentId: null,
        courseId: null,
        regular_score: 0,
        exam_score: 0,
        weight: 0.3
      };
    }
  }
};
</script>
<style scoped>
.message {
  margin-top: 10px;
  color: green;
}
</style>

login_index.vue

```html
<template>
  <div class="login-container">
    <div class="login-card">
      <h2 class="login-title">登录</h2>
      <form @submit.prevent="handleLogin">
        <div class="form-item">
          <label for="id">ID:</label>
          <input type="text" id="id" v-model="loginForm.id" required>
        </div>
        <div class="form-item">
          <label for="role">角色:</label>
          <select id="role" v-model="loginForm.role">
            <option value="teacher">教师</option>
            <option value="student">学生</option>
            <option value="monitor">班长</option>
          </select>
        </div>
        <div class="form-item">
          <button type="submit">登录</button>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  data() {
    return {
      loginForm: {
        id: '',
        role: '',
      },
      message: '',
      classId: '',
    };
  },
  methods: {
    handleLogin() {

      console.log(this.loginForm);
      axios
        .post('http://localhost:8081/api/login', this.loginForm)
       .then((response) => {
          if (response.data.success) {
            this.message = response.data.message;
            this.classId = response.data.classId;
            // 根据角色跳转到不同的页面
            switch (this.loginForm.role) {
              case 'teacher':
                this.$router.push({ path: '/teacherpage', query: { userId: this.loginForm.id } });
                break;
              case 'student' :
                this.$router.push({path:'/student_index',query : {userId:this.loginForm.id,role:this.loginForm.role}});
                break;
              case 'monitor':
                /* this.$router.push('/class-monitor'); */
                this.$router.push({path:'/student_index',query : {userId:this.loginForm.id,role:this.loginForm.role,classId:this.classId}});
                break;
              default:
                alert('请选择一个角色');
            }
          } else {
            this.message = response.data.message;
          }
        })
        .catch((error) => {
          console.error('Error:', error);
          this.message = '登录失败,请重试';
        });
    },
  },
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f0f2f5;
}

.login-card {
  width: 30%;
  padding: 20px;
  background-color: white;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.login-title {
  text-align: center;
  margin-bottom: 20px;
}

.form-item {
  margin-bottom: 15px;
}

.form-item label {
  display: block;
  margin-bottom: 5px;
}

.form-item input,
.form-item select {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  width: 100%;
  padding: 10px;
  background-color: #409eff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
}

button:hover {
  background-color: #66b1ff;
}
</style>

student_index.vue

<template>
  <div class="student-view" style="width:59%;margin: auto;">
    <h2 style="margin-left: 400px;">成绩查询</h2>
    <button @click="fetchGrade" style="margin-left: 420px;">查询</button>
    <div v-if="isMonitor">
      <button @click="viewAllGrades">查询全班成绩</button>
      <button @click="sortAllGrades">排序全班成绩</button>
    </div>
    <el-table :data="grades" border style="width: 100%">
      <el-table-column fixed prop="id" label="序号" width="50">
      </el-table-column>
      <el-table-column prop="stuId" label="学生id" width="100">
      </el-table-column>
      <el-table-column prop="sName" label="姓名" width="100">
      </el-table-column>
      <el-table-column prop="classId" label="所属班级" width="100">
      </el-table-column>
      <el-table-column prop="courseName" label="课程名称" width="130">
      </el-table-column>
      <el-table-column prop="regular_score" label="平时成绩" width="100">
      </el-table-column>
      <el-table-column prop="exam_score" label="期末成绩" width="100">
      </el-table-column>
      <el-table-column prop="final_score" label="最终成绩" width="100">
      </el-table-column>
      <el-table-column prop="weight" label="平时成绩占比" width="120">
      </el-table-column>
    </el-table>
  </div>
</template>
  
  <script>
  import { GetAllGradesByClassId, GetGradeByStudentId, SortAllGrade } from '@/api/gradeService';
  export default {
    name:'sty=udent_index',
    data() {
      return {
        studentId:null,
        classId:null,
        grades: [],
        role:null
      };
    },
    created() {
      this.role=this.$route.query.role;
      console.log("角色:",this.role);
    },
    computed: {
    isMonitor() {
      return this.role === "monitor"; // 确保角色判断是正确的
    },
  },
    methods: {
       fetchGrade() {
        //this.clearForm();
        this.studentId=this.$route.query.userId;
        console.log("学生ID:",this.studentId);
        GetGradeByStudentId(this.studentId)
        .then((Response)=>{
          this.grades=Response.data;
          console.log("查询到的成绩:",this.grades);
        })
        .catch(error=>{
          console.error("未查询到成绩:",error);
        });
    },
    viewAllGrades() {
      //this.clearForm();
      this.classId=this.$route.query.classId;
      console.log("班级ID:",this.classId);
      GetAllGradesByClassId(this.classId)
      .then((Response)=>{
          console.log("查询到的全班成绩Response:",Response.data);
          this.grades=Response.data;
          console.log("查询到的全班成绩:",this.grades.total_score);
      })
      .catch(error=>{
          console.error("未查询到全班成绩:",error);
      });
  },
  sortAllGrades() {
    this.classId=this.$route.query.classId;
      SortAllGrade(this.classId)
      .then((Response)=>{
        this.grades=Response.data;
        console.log("排序后的全班成绩:",this.grades);
      })
      .catch(error=>{
        console.error("未排序全班成绩:",error);
      })
  },
  clearForm() {
      this.grade = {
        studentId: null,
        courseId: null,
        regular_score: 0,
        exam_score: 0,
        weight: 0.3
      };
    }
}
}
  </script>
  <style scoped>
  
  </style>

App.vue

<template>
  <router-view></router-view>
</template>
<script setup lang="ts">

</script>
<style>

</style>

main.js

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.config.productionTip = false
Vue.use(ElementUI);
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

router/ index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
// import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  /* {
    path: '/',
    name: 'home',
    component: HomeView
  }, */
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // },
  {
    path:'/login',
    name:'login',
    component:()=>import('../views/system/login_index.vue')
  },
  {
    path:'/student_index',
    name:'student_index',
    component:()=>import('../views/system/student_index.vue')
  },
  {
    path:'/teacherpage',
    name:'teacherpage',
    component:()=>import('../views/system/grades_input.vue')
  },

]

const router = new VueRouter({
  routes
})

export default router

api/gradeService.js

// src/api/gradeService.js
import axios from 'axios';

const API_URL = 'http://localhost:8081';

export const addGrade = (gradeData) => {
    return axios.post(`${API_URL}/add`, gradeData);
};
export const GetAllGradesByClassId = (classId) => {
    return axios.get(`${API_URL}/monitor/${classId}`);
}
export const SortAllGrade=(classId)=>{
    return axios.get(`${API_URL}/monitor/${classId}/sort`)
}
export const GetAllGradesByteacherId = (teacherId) => {
    return axios.get(`${API_URL}/teacher/${teacherId}`)};

export const GetGradeByStudentId=(studentId)=>{
    return axios.get(`${API_URL}/student/${studentId}`)
}

assert的照片

后端在这里插入图片描述

在这里插入图片描述

启动类:

package cn.nike.hd4;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
/*@ComponentScan(basePackages = {"cn.nike"})
@MapperScan("cn.nike.hd4.dao")*/
public class Hd4Application {

    public static void main(String[] args) {
        SpringApplication.run(Hd4Application.class, args);
    }

}

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>cn.nike</groupId>
    <artifactId>hd4</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>hd4</name>
    <description>hd4</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>3.0.3</version>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.0</version> &lt;!&ndash; 根据需要调整版本 &ndash;&gt;
        </dependency>-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter-test</artifactId>
            <version>3.0.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

application.properties

spring.application.name=hd4
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/webzygrade
spring.datasource.username=root
spring.datasource.password=123456
server.port=8081
#logging.level.root=DEBUG

Controller层:

GradeController.java:
package cn.nike.hd4.Controller;

import cn.nike.hd4.Service.GradeService;
import cn.nike.hd4.entity.FPGrade;
/*import cn.nike.hd4.entity.Grade;*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
/*@MapperScan("cn.nike.hd4.dao")*/
@CrossOrigin(origins = "http://localhost:8080")
public class GradeController {
    @Autowired
    private GradeService gradeService;
    @RequestMapping("/teacher/{userId}")
    public List<FPGrade> getAllGradebyteacherId(@PathVariable Integer userId) {
        //System.out.println("User list size: " + getAllGradeByteacherId().size());
        return gradeService.getAllgradeByteacherid(userId);
    }
    //老师对学生成绩的录入
    @PutMapping("/update/{gradeId}")
    public ResponseEntity<FPGrade> updateGrade(@PathVariable Integer gradeId, @RequestBody FPGrade grade) {
        double regular_score=grade.getRegular_score();
        double exam_score=grade.getExam_score();
        double weight=grade.getWeight();
        FPGrade updategrade=gradeService.UpdategradeById(gradeId,regular_score,exam_score,weight);
        return ResponseEntity.ok(updategrade);
    }
    @RequestMapping("/student/{stuId}")
    public List<FPGrade> GetGradeByStudentId(@PathVariable Integer stuId) {
        return gradeService.FindByStudentId(stuId);
    }
    @RequestMapping("/monitor/{classId}")
    public List<FPGrade> GetAllGradesByClassId(@PathVariable Integer classId) {
        return gradeService.FindByClassId(classId);
    }
    @RequestMapping("/monitor/{classId}/sort")
    public List<FPGrade> SortAllGrade(@PathVariable Integer classId) {
        return gradeService.SortAllGrade(classId);
    }

}


LoginController.java:

package cn.nike.hd4.Controller;
import cn.nike.hd4.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class LoginController {
    @Autowired
    private UserService userService;
    @PostMapping("/api/login")
    public ResponseEntity<?> login(@RequestBody LoginRequest loginRequest) {
        Integer id = LoginRequest.getId();
        String role = LoginRequest.getRole();
        System.out.println("执行了登入");
        // 验证逻辑,
        if (id != null && userService.login(id,role)) {
            return ResponseEntity.ok().body(new LoginResponse(true, "登录成功",userService.GetClassIdById(id)));
        } else {
            return ResponseEntity.status(401).body(new LoginResponse(false, "ID或角色不匹配",null));
        }
    }
    //
    static class LoginRequest {
        private static Integer id;
        private static String role;

        public static Integer getId() {
            return id;
        }

        public  void setId(Integer id) {
            this.id = id;
        }

        public static String getRole() {
            return role;
        }

        public void setRole(String role) {
            this.role = role;
        }
        // getters and setters
    }

    static class LoginResponse {
        private boolean success;
        private String message;
        /*private String role;*/
        //登入时返回班级id
        private Integer classId;

        public LoginResponse(boolean success, String message,Integer classId) {
            this.success = success;
            this.message = message;
            /*this.role = role;*/
            this.classId = classId;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
        public Integer getClassId() {
            return classId;
        }

        public void setClassId(Integer classId) {
            this.classId = classId;
        }

        public boolean isSuccess() {
            return success;
        }

        public void setSuccess(boolean success) {
            this.success = success;
        }
        // getters and setters
    }
}


Service层:
GradeService.java:

package cn.nike.hd4.Service;
import cn.nike.hd4.dao.GradeMapper;
import cn.nike.hd4.entity.FPGrade;
import cn.nike.hd4.exception.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.List;

@Service
public class GradeService {
    @Autowired
    private GradeMapper gradeMapper;
    public List<FPGrade> FindByStudentId(int studentId){
        return gradeMapper.FindByStudentId(studentId);
    }
    public List<FPGrade> FindByClassId(int classId){
        System.out.println("查找结果:");
        System.out.println(gradeMapper.FindByClassId(classId));
        return gradeMapper.FindByClassId(classId);
    }
    //班长可以实现对所有成绩进行排序
    public List<FPGrade> SortAllGrade(int classId){
        return gradeMapper.SortAllGrade(classId);
    }
    public List<FPGrade>getAllgradeByteacherid(Integer id){
        return gradeMapper.getlistByteacherid(id);
    }
    public FPGrade UpdategradeById(Integer id,double regular_score,double exam_score,double weight){
        FPGrade grade = gradeMapper.FindByGradeid(id);
        //不为空  则进行成绩的更新
        if(grade!=null){
            grade.calculatefinalscore(regular_score,exam_score,weight);
            double final_score=grade.getFinal_score();
            // 使用 DecimalFormat 保留一位小数
            DecimalFormat df = new DecimalFormat("#.#");
            final_score = Double.parseDouble(df.format(final_score));
            gradeMapper.updateGrade(id,regular_score,exam_score,final_score,weight);
            return grade;
        }else {
            throw new ResourceNotFoundException("Grade not found");
        }
    }
}

UserService.java

package cn.nike.hd4.Service;
import cn.nike.hd4.dao.GradeMapper;
import cn.nike.hd4.entity.FPGrade;
import cn.nike.hd4.exception.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.List;

@Service
public class GradeService {
    @Autowired
    private GradeMapper gradeMapper;
    public List<FPGrade> FindByStudentId(int studentId){
        return gradeMapper.FindByStudentId(studentId);
    }
    public List<FPGrade> FindByClassId(int classId){
        System.out.println("查找结果:");
        System.out.println(gradeMapper.FindByClassId(classId));
        return gradeMapper.FindByClassId(classId);
    }
    //班长可以实现对所有成绩进行排序
    public List<FPGrade> SortAllGrade(int classId){
        return gradeMapper.SortAllGrade(classId);
    }
    public List<FPGrade>getAllgradeByteacherid(Integer id){
        return gradeMapper.getlistByteacherid(id);
    }
    public FPGrade UpdategradeById(Integer id,double regular_score,double exam_score,double weight){
        FPGrade grade = gradeMapper.FindByGradeid(id);
        //不为空  则进行成绩的更新
        if(grade!=null){
            grade.calculatefinalscore(regular_score,exam_score,weight);
            double final_score=grade.getFinal_score();
            // 使用 DecimalFormat 保留一位小数
            DecimalFormat df = new DecimalFormat("#.#");
            final_score = Double.parseDouble(df.format(final_score));
            gradeMapper.updateGrade(id,regular_score,exam_score,final_score,weight);
            return grade;
        }else {
            throw new ResourceNotFoundException("Grade not found");
        }
    }
}

dao层:
GradeMapper.java

package cn.nike.hd4.dao;
import cn.nike.hd4.entity.FPGrade;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@Mapper
public interface GradeMapper {
  /*  @Select("select * from grade")
    public List<Grade> list();*/
    //根据老师id能够获取全部学生信息
    @Select("select g.id,g.regular_score,g.exam_score,g.total_score ,"+
            "g.weight,g.student_id as stuId,u.class_id as classId,u.name as sName,c.name as courseName"+
            " from grade g,course c,user u"+" where g.student_id=u.id and " +
            "g.course_id=c.id and teacher_id=#{id} order by course_id")
    public List<FPGrade>getlistByteacherid(@Param("id") Integer id);
   //根据成绩表的id查询某一条成绩
    @Select("select * from grade where id=#{Gradeid}")
    public FPGrade FindByGradeid(Integer Gradeid);
    //更新学生的每条信息(老师录入功能)
   @Update("update grade set regular_score=#{regular_score},exam_score=#{exam_score}," +
           "total_score=#{final_score},weight=#{weight} where id=#{gradeid}")
    public int updateGrade(@Param("gradeid") Integer gradeid,double regular_score,
                           double exam_score,double final_score,double weight);
   //根据学生id查找其成绩相关信息
   @Select("select g.id,g.regular_score,g.exam_score,g.total_score,g.weight,g.student_id as studentId" +
           ",c.name as courseName,u.name as sName,u.class_id as classId from grade g,course c,user u  where g.student_id=u.id and" +
           " g.course_id=c.id and g.student_id=#{studentId}")
   public List<FPGrade> FindByStudentId(Integer studentId);
    //根据班级id查询班级所有同学成绩信息
   @Select("select g.id,g.regular_score,g.exam_score,g.total_score,g.weight,g.student_id as studentId" +
            ",c.name as courseName,u.name as sName,u.class_id as classId from grade g,course c,user u  where g.student_id=u.id and" +
            " g.course_id=c.id and u.class_id=#{classId} ")
    public List<FPGrade> FindByClassId(Integer classId);
    //班长对全班成绩进行排序(按照总成绩降序  课程编号升序)
    @Select("select g.id,g.regular_score,g.exam_score,g.total_score,g.weight,g.student_id as studentId" +
            ",c.name as courseName,u.name as sName,u.class_id as classId from grade g,course c,user u  where g.student_id=u.id and" +
            " g.course_id=c.id and u.class_id=#{classId} order by course_id desc,total_score desc")
    public List<FPGrade>SortAllGrade(Integer classId);
}

UserMapper.java

package cn.nike.hd4.dao;
import cn.nike.hd4.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface UserMapper {
    //根据用户id查询角色
    @Select("select role from user where id=#{id}")
    public String RoleById(Integer id);
    //根据用户id查询其所在班级(只是给班长使用)
    @Select("select class_id from user where id=#{id}")
    public Integer GetClassId(Integer id);
}

entity:
FPGrade.java

package cn.nike.hd4.entity;
public class FPGrade {
    private Integer number;
    private Integer id;
    private Integer classId;  //所属班级id
    private Integer studentId;
    private String sName;  //学生姓名
    private String  courseName; //课程名称
    private double regular_score;
    private double exam_score;
    private double total_score;
    private double weight;

    public FPGrade(Integer number,Integer classId, String courseName,
                   double exam_score, double final_score,
                   Integer id, double regular_score,
                   String sName, double weight,Integer stuId) {
        this.number = number;
        this.classId = classId;
        this.courseName = courseName;
        this.exam_score = exam_score;
        this.total_score = final_score;
        this.id = id;
        this.regular_score = regular_score;
        this.sName = sName;
        this.weight = weight;
        this.studentId = stuId;
    }
    public void calculatefinalscore(double regular_score,double exam_score,double weight) {
        this.total_score = regular_score*weight + exam_score*(1-weight);
        setFinal_score(total_score);
    }
    public FPGrade() {}
    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }
    public Integer getClassId() {
        return classId;
    }

    public void setClassId(Integer classId) {
        this.classId = classId;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public double getExam_score() {
        return exam_score;
    }

    public void setExam_score(double exam_score) {
        this.exam_score = exam_score;
    }

    public double getFinal_score() {
        return total_score;
    }

    public void setFinal_score(double final_score) {
        this.total_score = final_score;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public double getRegular_score() {
        return regular_score;
    }

    public void setRegular_score(double regular_score) {
        this.regular_score = regular_score;
    }

    public String getsName() {
        return sName;
    }

    public void setsName(String sName) {
        this.sName = sName;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public Integer getStuId() {
        return studentId;
    }

    public void setStuId(Integer studentId) {
        this.studentId = studentId;
    }

    @Override
    public String toString() {
        return "FPGrade{" +
                "classId=" + classId +
                ", id=" + id +
                ", stuId=" + studentId +
                ", sName='" + sName + '\'' +
                ", courseName='" + courseName + '\'' +
                ", regular_score=" + regular_score +
                ", exam_score=" + exam_score +
                ", final_score=" + total_score +
                ", weight=" + weight +
                '}';
    }
}

User.java

package cn.nike.hd4.entity;
public class User {
    private Integer id;
    private String name;
    private String role;
    private Integer class_id;

    public User(Integer class_id, Integer id, String name, String role) {
        this.class_id = class_id;
        this.id = id;
        this.name = name;
        this.role = role;
    }

    public Integer getClass_id() {
        return class_id;
    }

    public void setClass_id(Integer class_id) {
        this.class_id = class_id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }
    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", role='" + role + '\'' +
                ", class_id=" + class_id +
                '}';
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值