|
|
|
@ -1,63 +1,113 @@
|
|
|
|
|
package com.zsz.controller;
|
|
|
|
|
|
|
|
|
|
// 导入 MyBatis-Plus 分页插件的 Page 类,用于实现分页查询
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
// 导入学生实体类,用于封装学生信息
|
|
|
|
|
import com.zsz.pojo.Student;
|
|
|
|
|
// 导入学生服务类,用于调用学生相关的业务逻辑
|
|
|
|
|
import com.zsz.service.StudentService;
|
|
|
|
|
// 导入 MD5 加密工具类,用于对学生密码进行加密处理
|
|
|
|
|
import com.zsz.util.MD5;
|
|
|
|
|
// 导入自定义的结果类,用于封装接口返回的数据
|
|
|
|
|
import com.zsz.util.Result;
|
|
|
|
|
// 导入 Swagger 注解,用于生成 API 文档
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
|
// 导入 Spring 框架的自动注入注解和 Web 相关注解
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 学生控制器,处理与学生信息相关的 HTTP 请求
|
|
|
|
|
*/
|
|
|
|
|
@Api("学生控制器")
|
|
|
|
|
// 标识该类为 RESTful 风格的控制器
|
|
|
|
|
@RestController
|
|
|
|
|
// 设置该控制器处理的请求路径前缀
|
|
|
|
|
@RequestMapping("/sms/studentController")
|
|
|
|
|
public class StudentController {
|
|
|
|
|
|
|
|
|
|
// 自动注入学生服务类的实例,用于调用学生相关的业务逻辑
|
|
|
|
|
@Autowired
|
|
|
|
|
StudentService studentService;
|
|
|
|
|
|
|
|
|
|
// http://localhost:8080/sms/studentController/getStudentByOpr/1/3?clazzName=&name=
|
|
|
|
|
/**
|
|
|
|
|
* 根据分页条件获取学生分页数据
|
|
|
|
|
* 请求 URL 示例:http://localhost:8080/sms/studentController/getStudentByOpr/1/3?clazzName=&name=
|
|
|
|
|
* @param pageNo 分页查询的页码数
|
|
|
|
|
* @param pageSize 分页查询的页大小
|
|
|
|
|
* @param student 学生信息,可用于条件查询
|
|
|
|
|
* @return 封装了分页学生数据的结果对象
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("根据分页条件获取学生分页数据")
|
|
|
|
|
// 处理 GET 请求,路径中包含页码和页大小的占位符
|
|
|
|
|
@GetMapping("/getStudentByOpr/{pageNo}/{pageSize}")
|
|
|
|
|
public Result getStudentByOpr(
|
|
|
|
|
// 从路径中获取页码数,并使用 Swagger 注解进行参数描述
|
|
|
|
|
@ApiParam("分页查询的页码数") @PathVariable("pageNo") Integer pageNo,
|
|
|
|
|
// 从路径中获取页大小,并使用 Swagger 注解进行参数描述
|
|
|
|
|
@ApiParam("分页查询的页大小") @PathVariable("pageSize") Integer pageSize,
|
|
|
|
|
// 从请求参数中获取学生信息对象,并使用 Swagger 注解进行参数描述
|
|
|
|
|
@ApiParam("学生信息") Student student
|
|
|
|
|
){
|
|
|
|
|
// 创建一个 Page 对象,用于封装分页信息
|
|
|
|
|
Page<Student> studentPage = new Page<>(pageNo,pageSize);
|
|
|
|
|
// 调用学生服务类的方法,根据分页信息和学生信息进行查询
|
|
|
|
|
Page<Student> studentPage1 = studentService.getStudentData(studentPage,student);
|
|
|
|
|
// 将查询结果封装到自定义的结果对象中并返回
|
|
|
|
|
return Result.ok(studentPage1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// http://localhost:8080/sms/studentController/addOrUpdateStudent
|
|
|
|
|
/**
|
|
|
|
|
* 新增或更改学生信息
|
|
|
|
|
* 请求 URL 示例:http://localhost:8080/sms/studentController/addOrUpdateStudent
|
|
|
|
|
* @param student 请求中携带的要修改信息的学生对象
|
|
|
|
|
* @return 封装了操作结果的结果对象
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("新增或更改学生信息")
|
|
|
|
|
// 处理 POST 请求
|
|
|
|
|
@PostMapping("/addOrUpdateStudent")
|
|
|
|
|
public Result addOrUpdateStudent(
|
|
|
|
|
// 从请求体中获取学生信息对象,并使用 Swagger 注解进行参数描述
|
|
|
|
|
@ApiParam("请求中携带的要修改信息的学生对象") @RequestBody Student student
|
|
|
|
|
){
|
|
|
|
|
// 获取学生的 ID
|
|
|
|
|
Integer id = student.getId();
|
|
|
|
|
// 判断学生 ID 是否为空或为 0,如果是则表示新增学生信息
|
|
|
|
|
if (null == id || 0 == id){
|
|
|
|
|
// 获取学生的密码
|
|
|
|
|
String password = student.getPassword();
|
|
|
|
|
// 使用 MD5 加密工具类对密码进行加密处理
|
|
|
|
|
String encrypt = MD5.encrypt(password);
|
|
|
|
|
// 将加密后的密码重新设置到学生对象中
|
|
|
|
|
student.setPassword(encrypt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 调用学生服务类的方法,保存或更新学生信息
|
|
|
|
|
studentService.saveOrUpdate(student);
|
|
|
|
|
// 返回操作成功的结果对象
|
|
|
|
|
return Result.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// http://localhost:8080/sms/studentController/delStudentById
|
|
|
|
|
/**
|
|
|
|
|
* 删除单个或多个学生信息
|
|
|
|
|
* 请求 URL 示例:http://localhost:8080/sms/studentController/delStudentById
|
|
|
|
|
* @param ids 要删除的学生 id 的集合
|
|
|
|
|
* @return 封装了操作结果的结果对象
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("删除单个或多个学生信息")
|
|
|
|
|
// 处理 DELETE 请求
|
|
|
|
|
@DeleteMapping("/delStudentById")
|
|
|
|
|
public Result delStudentById(
|
|
|
|
|
@ApiParam("要删除的学生id的集合") @RequestBody List<Integer> ids
|
|
|
|
|
// 从请求体中获取要删除的学生 ID 集合,并使用 Swagger 注解进行参数描述
|
|
|
|
|
@ApiParam("要删除的学生 id 的集合") @RequestBody List<Integer> ids
|
|
|
|
|
){
|
|
|
|
|
// 调用学生服务类的方法,根据 ID 集合删除学生信息
|
|
|
|
|
studentService.removeByIds(ids);
|
|
|
|
|
// 返回操作成功的结果对象
|
|
|
|
|
return Result.ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|