11.30

今天实现后端代码

UserController

package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.Student;
import com.example.pojo.Teacher;
import com.example.pojo.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/getByUser")
    public ResponseEntity<Integer> getByUser(String username, String password, String position) {
        int re = userService.getByUser(username, password, position);
        return ResponseEntity.ok(re);
    }
    @PostMapping("/addUser")
    public Result add(@RequestBody User user) {
        userService.add(user);
        return Result.success(user);
    }
    //添加教师信息
    @PostMapping("/addTea")
    public Result addTea(@RequestBody Teacher teacher) {
        userService.addTea(teacher);
        return Result.success(teacher);
    }
    @PostMapping("/addStu")
    public Result addTea(@RequestBody Student student) {
        userService.addStu(student);
        return Result.success(student);
    }
}

TeacherController

package com.example.controller;

import com.example.pojo.Course;
import com.example.pojo.Result;
import com.example.pojo.Teacher;
import com.example.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @GetMapping("/getName/{username}")
    public Result getName(@PathVariable("username") String username) {
        return Result.success(teacherService.getName(username));
    }

    @PostMapping("/addCourse")
    public Result addCourse(@RequestBody Course course) {
        teacherService.addCourse(course);
        return Result.success(course);
    }

    @PostMapping("/updateTea")
    public Result update(@RequestBody Teacher teacher) {
        teacherService.updateTea(teacher);
        return Result.success(teacher);
    }

    @GetMapping("/getByName/{name}")
    public Result getByName(@PathVariable("name") String name) {
        return Result.success(teacherService.getByName(name));
    }

    @GetMapping("/getAll/{username}")
    public Result getAll(@PathVariable("username") String username) {
        return Result.success(teacherService.getAll(username));
    }

    @GetMapping("/getCourse/{name}")
    public Result getCourse(@PathVariable("name") String name) {
        return Result.success(teacherService.getCourse(name));
    }
}

StudentController

package com.example.controller;

import com.example.pojo.Information;
import com.example.pojo.Result;
import com.example.pojo.Student;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/getName/{username}")
    public Result getName(@PathVariable("username") String username) {
        return Result.success(studentService.getName(username));
    }

    @PostMapping("/updateStu")
    public Result update(@RequestBody Student student) {
        studentService.update(student);
        return Result.success(student);
    }

    @GetMapping("/select")
    public Result select() {
        return Result.success(studentService.select());
    }

    @GetMapping("/selectCourse/{name}")
    public Result selectCourse(@PathVariable("name") String name) {
        return Result.success(studentService.selectCourse(name));
    }

    @GetMapping("/selectAll/{name}")
    public Result selectAll(@PathVariable("name") String name) {
        return Result.success(studentService.selectAll(name));
    }

    @GetMapping("/choose")
    public Result choose() {
        return Result.success(studentService.select());
    }

    @PostMapping("/choose1")
    public Result choose1(@RequestBody Information information) {
        studentService.choose1(information);
        return Result.success(information);
    }

    @PostMapping("/updateCourse/{id}/{count}")
    public Result updateCourse(@PathVariable("id") String id, @PathVariable("count") String count) {
        studentService.updateCourse(id, count);
        return Result.success(studentService.selectCourse(id));
    }

    @GetMapping("/cc/{id}")
    public Result cc(@PathVariable("id") String id) {
        return Result.success(studentService.cc(id));
    }

    @GetMapping("/getInformation/{name}")
    public Result getInformation(@PathVariable("name") String name) {
        return Result.success(studentService.getInformation(name));
    }
}

 

posted @ 2023-12-18 12:46  七安。  阅读(4)  评论(0编辑  收藏  举报