首页>代码>基于SpringBoot+Vue的学生选课管理系统代码分享>/student_server/src/main/java/com/auggie/student_server/controller/StudentController.java
package com.auggie.student_server.controller;

import com.auggie.student_server.entity.Student;
import com.auggie.student_server.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Auther: auggie
 * @Date: 2022/2/8 17:37
 * @Description: StudentController
 * @Version 1.0.0
 */

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

    @PostMapping("/addStudent")
    public boolean addStudent(@RequestBody Student student) {
        System.out.println("正在保存学生对象" + student);
        return studentService.save(student);
    }

    @PostMapping("/login")
    public boolean login(@RequestBody Student student) {
        System.out.println("正在验证学生登陆 " + student);
        Student s = studentService.findById(student.getSid());
        if (s == null || !s.getPassword().equals(student.getPassword())) {
            return false;
        }
        else {
            return true;
        }
    }

    @PostMapping("/findBySearch")
    public List<Student> findBySearch(@RequestBody Student student) {
        Integer fuzzy = (student.getPassword() == null) ? 0 : 1;
        return studentService.findBySearch(student.getSid(), student.getSname(), fuzzy);
    }

    @GetMapping("/findById/{sid}")
    public Student findById(@PathVariable("sid") Integer sid) {
        System.out.println("正在查询学生信息 By id " + sid);
        return studentService.findById(sid);
    }

    @GetMapping("/findByPage/{page}/{size}")
    public List<Student> findByPage(@PathVariable("page") int page, @PathVariable("size") int size) {
        System.out.println("查询学生列表分页 " + page + " " + size);
        return studentService.findByPage(page, size);
    }

    @GetMapping("/getLength")
    public Integer getLength() {
        return studentService.getLength();
    }

    @GetMapping("/deleteById/{sid}")
    public boolean deleteById(@PathVariable("sid") int sid) {
        System.out.println("正在删除学生 sid:" + sid);
        return studentService.deleteById(sid);
    }

    @PostMapping("/updateStudent")
    public boolean updateStudent(@RequestBody Student student) {
        System.out.println("更新 " + student);
        return studentService.updateById(student);
    }
}
最近下载更多
陈小灏  LV18 2月21日
zolscy  LV24 2024年11月26日
krispeng  LV15 2024年11月12日
lanyuhao  LV2 2024年6月18日
wanglinddad  LV55 2024年3月24日
Demo1111  LV30 2024年3月6日
hyx666110  LV2 2024年3月1日
Boss绝  LV9 2024年2月26日
全栈小陈  LV4 2024年1月21日
zhangjilu  LV18 2023年12月31日
最近浏览更多
linalina 6月3日
暂无贡献等级
yangchengshuai  LV15 3月7日
z96141176 2月23日
暂无贡献等级
陈小灏  LV18 2月21日
cherrylxj  LV3 1月13日
wwb521  LV7 1月6日
牛牛要爆炸了  LV2 1月2日
微信网友_6955249237250048  LV5 2024年12月28日
taoshen95  LV16 2024年12月16日
曾多次  LV1 2024年12月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友