You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
3.0 KiB
98 lines
3.0 KiB
package com.yanzhen.controller;
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.yanzhen.entity.Grade;
|
|
import com.yanzhen.entity.Org;
|
|
import com.yanzhen.entity.Student;
|
|
import com.yanzhen.service.GradeService;
|
|
import com.yanzhen.service.OrgService;
|
|
import com.yanzhen.service.StudentService;
|
|
import com.yanzhen.utils.Result;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Map;
|
|
|
|
//学生管理的控制器
|
|
@RestController
|
|
@RequestMapping("/student")
|
|
public class StudentController {
|
|
//注入实例
|
|
//注入学生服务类
|
|
@Autowired
|
|
private StudentService studentService;
|
|
//注入成绩服务类
|
|
@Autowired
|
|
private GradeService gradeService;
|
|
//注入组织服务类
|
|
@Autowired
|
|
private OrgService orgService;
|
|
//创建新的实例
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody Student student){
|
|
//在学生管理服务类中引用create方法
|
|
int flag = studentService.create(student);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//删除学生信息
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//在学生管理服务类中引用delete方法
|
|
int flag = studentService.delete(ids);
|
|
//判断是否删除成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//更新学生信息
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody Student student){
|
|
//在学生管理服务类中引用update方法
|
|
int flag = studentService.updateSelective(student);
|
|
//判断是否更新成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//获取学生详细信息
|
|
@GetMapping("detail")
|
|
public Student detail(Integer id){
|
|
//返回结果
|
|
return studentService.detail(id);
|
|
}
|
|
//查询学生信息
|
|
@PostMapping("query")
|
|
public Map<String,Object> query(@RequestBody Student student){
|
|
//创建分页对象
|
|
PageInfo<Student> pageInfo = studentService.query(student);
|
|
// 遍历查询结果中的每个学生
|
|
pageInfo.getList().forEach(entity->{
|
|
// 根据学生的年级 ID 获取对应的年级信息。
|
|
Grade grade = gradeService.detail(entity.getGradeId());
|
|
// 成绩信息设置到学生中
|
|
entity.setGrade(grade);
|
|
// 根据学生的班级 ID 获取对应的班级信息。
|
|
Org org = orgService.detail(entity.getClazzId());
|
|
// 将班级信息设置到学生对象中。
|
|
entity.setOrg(org);
|
|
});
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
|
|
} |