Shang Silicon Valley Smart Campus - 4. Class Management

content

1. Echo the grade option in the search criteria

1.1. Add a method to the controller

2. Query class information (pagination with conditions)

2.1. Add methods to service and its implementation class

2.2. Add method to controller

3. Add and modify class information

3.1. Add a method to the controller

4. Delete and batch delete class information

4.1. Add a method to the controller.


After clicking class management, you need to query class information by page and query class information according to grade.

1. Echo the grade option in the search criteria

Request path: /sms/gradeController/getGrades

1.1. Add a method to the controller

It is found here that in the same controller class, the method name can be the same

GradeController

    /**
     * 获取全部年级
     * @return
     */
    @ApiOperation("获取全部年级")
    @GetMapping("/getGrades")
    public Result getGrades(){
        List<Grade> gradeList = gradeService.list();
        return Result.ok(gradeList);
    }

2. Query class information (pagination with conditions)

The request path is: /sms/clazzController/getClazzsByOpr/{pageNo}/{pageSize}?gradeName=xxx&name=xxx

2.1. Add methods to service and its implementation class

ClazzService

public interface ClazzService extends IService<Clazz> {

    /**
     * 查询班级信息(分页带条件)
     * @param page
     * @param clazz 分页查询的条件
     * @return
     */
    IPage<Clazz> getClazzByOpr(Page<Clazz> page, Clazz clazz);

}

ClazzServiceImpl

@Api(tags = "班级管理器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    /**
     * 查询班级信息(分页带条件)
     * 请求路径为:/sms/clazzController/getClazzsByOpr/{pageNo}/{pageSize}?gradeName=xxx&name=xxx
     * @param pageNo 分页查询的页码
     * @param pageSize 分页查询每页的数据量
     * @param clazz 分页查询的查询条件
     * @return
     */
    @ApiOperation("查询班级信息(分页带条件)")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzByOpr(
            @ApiParam("分页查询的页码") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("分页查询每页的数据量") @PathVariable("pageSize") Integer pageSize,
            // 使用Clazz对象来接收gradeName和name
            @ApiParam("分页查询的查询条件") Clazz clazz
    ){
        Page<Clazz> page = new Page<>(pageNo, pageSize);
        IPage<Clazz> clazzIPage = clazzService.getClazzByOpr(page, clazz);
        return Result.ok(clazzIPage);
    }

}

2.2. Add method to controller

ClazzController

@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    /**
     * 查询班级信息(分页带条件)
     * 请求路径为:/sms/clazzController/getClazzsByOpr/1/3?gradeName=xxx&name=xxx
     * @param pageNo 分页查询的页码
     * @param pageSize 分页查询每页的数据量
     * @param clazz 分页查询的查询条件
     * @return
     */
    @ApiOperation("查询班级信息(分页带条件)")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzByOpr(
            @ApiParam("分页查询的页码") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("分页查询每页的数据量") @PathVariable("pageSize") Integer pageSize,
            // 使用Clazz对象来接收gradeName和name
            @ApiParam("分页查询的查询条件") Clazz clazz
    ){
        Page<Clazz> page = new Page<>(pageNo, pageSize);
        IPage<Clazz> clazzIPage = clazzService.getClazzByOpr(page, clazz);
        return Result.ok(clazzIPage);
    }

}

3. Add and modify class information

3.1. Add a method to the controller

    /**
     * 添加或修改班级信息
     * @param clazz JSON格式的班级信息
     * @return
     */
    @ApiOperation("添加或修改班级信息")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(
            @ApiParam("JSON格式的班级信息") @RequestBody Clazz clazz
    ){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }

4. Delete and batch delete class information

4.1. Add a method to the controller.

    /**
     * 删除或批量删除班级信息
     * @param ids 要删除的多个班级的ID的JSON数组
     * @return
     */
    @ApiOperation("删除或批量删除班级信息")
    @DeleteMapping("deleteClazz")
    public Result deleteClazz(
            @ApiParam("要删除的多个班级的ID的JSON数组") @RequestBody List<Integer> ids
    ){
        clazzService.removeByIds(ids);
        return Result.ok();
    }

Guess you like

Origin blog.csdn.net/Mr_zhangyj/article/details/124295176
Recommended