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.
91 lines
2.9 KiB
91 lines
2.9 KiB
package com.yanzhen.controller;
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.yanzhen.entity.DormitoryStudent;
|
|
import com.yanzhen.entity.Student;
|
|
import com.yanzhen.service.DormitoryService;
|
|
import com.yanzhen.service.DormitoryStudentService;
|
|
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("/dormitoryStudent")
|
|
public class DormitoryStudentController {
|
|
//注入实例
|
|
// 注入DormitoryStudent服务类
|
|
@Autowired
|
|
private DormitoryStudentService dormitoryStudentService;
|
|
//注入学生服务类
|
|
@Autowired
|
|
private StudentService studentService;
|
|
//注入宿舍服务类
|
|
@Autowired
|
|
private DormitoryService dormitoryService;
|
|
|
|
//创建新的实例
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody DormitoryStudent dormitoryStudent){
|
|
//在学生宿舍服务类引用create方法
|
|
int flag = dormitoryStudentService.create(dormitoryStudent);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//根据ID删除学生宿舍记录
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//在学生宿舍服务类引用delete方法
|
|
int flag = dormitoryStudentService.delete(ids);
|
|
//判断是否删除成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//更新学生宿舍记录
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody DormitoryStudent dormitoryStudent){
|
|
//在学生宿舍服务类引用update方法
|
|
int flag = dormitoryStudentService.update(dormitoryStudent);
|
|
//判断是否更新成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//获取学生宿舍记录详细信息
|
|
@GetMapping("detail")
|
|
public DormitoryStudent detail(Integer id){
|
|
//返回结果
|
|
return dormitoryStudentService.detail(id);
|
|
}
|
|
//查询学生宿舍记录
|
|
@PostMapping("query")
|
|
public Map<String,Object> query(@RequestBody DormitoryStudent dormitoryStudent){
|
|
//创建分页对象
|
|
PageInfo<DormitoryStudent> pageInfo = dormitoryStudentService.query(dormitoryStudent);
|
|
//遍历查询结果
|
|
pageInfo.getList().forEach(entity->{
|
|
//根据学生宿舍记录获取对应学生详细信息
|
|
Student detail = studentService.detail(entity.getStudentId());
|
|
entity.setStudent(detail);
|
|
});
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
} |