From b0b23648a457b0519ba667d0623ce5645ac0365f Mon Sep 17 00:00:00 2001 From: pb8qzmito <13100778657@163.com> Date: Mon, 7 Oct 2024 12:23:19 +0800 Subject: [PATCH] ADD file via upload --- StudentController.java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 StudentController.java diff --git a/StudentController.java b/StudentController.java new file mode 100644 index 0000000..d1d989e --- /dev/null +++ b/StudentController.java @@ -0,0 +1,37 @@ +package com.example.classroomattendance.controller; + +import com.example.classroomattendance.model.Student; +import com.example.classroomattendance.service.StudentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +@Controller +public class StudentController { + + @Autowired + private StudentService studentService; + + @PostMapping("/pick") + public String pickRandomStudent(Model model) { + Student pickedStudent = studentService.pickRandomStudent(); + model.addAttribute("pickedStudent", pickedStudent); + model.addAttribute("students", studentService.getAllStudents()); + return "index"; + } + + @PostMapping("/updatePoints") + public String updateStudentPoints(@RequestParam Long studentId, @RequestParam double points, Model model) { + studentService.updateStudentPoints(studentId, points); + model.addAttribute("pickedStudent", studentService.pickRandomStudent()); + model.addAttribute("students", studentService.getAllStudents()); + return "index"; + } + + @GetMapping("/") + public String listStudents(Model model) { + model.addAttribute("students", studentService.getAllStudents()); + return "index"; + } +} \ No newline at end of file