JavaCRUD模板参考

发布于:2024-05-14 ⋅ 阅读:(145) ⋅ 点赞:(0)

Mapper层

@Mapper
public interface ExCategoryMapper extends BaseMapper<ExCategory> {
}

Service层

package co.yixiang.exam.service;

import co.yixiang.exam.common.R;
import co.yixiang.exam.entity.ExStudent;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.data.domain.Pageable;

import java.util.List;

/**
 * @author Mtz
 * @version 1.0
 * @2024/5/138:55
 * @function
 * @comment
 */

public interface ExStudentService {
    /***
     * 学生模块分页查询
     * @param exStudent
     * @param pageable
     * @return
     */
    R<IPage<ExStudent>> selectInfo(ExStudent exStudent, Pageable pageable);

    /***
     * 学生模块添加
     * @param exStudent
     * @return R<Void>
     */
    R<Void> insertInfo(ExStudent exStudent);

    /***
     * 学生模块根据id修改
     * @param exStudent
     * @return
     */
    R<Void> saveInfo(ExStudent exStudent);

    /***
     * 学生模块根据id获取数据
     * @param exStudent
     * @return
     */
    R<ExStudent> getByIdInfo(ExStudent exStudent);

    /***
     * 学生模块根据集合id 批量删除数据
     * @param ids
     * @return   R<Void>
     */
    R<Void> removeIdsInfo(List<Integer> ids);
}

Controller层

package co.yixiang.exam.controller;

import co.yixiang.exam.common.R;
import co.yixiang.exam.entity.ExStudent;
import co.yixiang.exam.service.ExStudentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mtz
 * @version 1.0
 * @2024/5/139:35
 * @function
 * @comment 学生模块
 */
@RestController
@RequestMapping("/ex/student")
public class ExStudentController {
    @Autowired
    private ExStudentService exStudentService;


    /***
     * 学生模块分页查询
     * @param exStudent
     * @param pageable
     * @return R<IPage < ExStudent>>
     */
    @GetMapping("/selectInfo")
    public R<IPage<ExStudent>> selectInfo(ExStudent exStudent, Pageable pageable) {
        return exStudentService.selectInfo(exStudent, pageable);
    }

    /***
     * 学生模块添加
     * @param exStudent
     * @return R<Void>
     */
    @PostMapping("/insertInfo")
    public R<Void> insertInfo(@RequestBody ExStudent exStudent) {
        return exStudentService.insertInfo(exStudent);
    }

    /***
     * 学生模块根据id修改数据
     * @param exStudent
     * @return
     */
    @PostMapping("/saveInfo")
    public R<Void> saveInfo(@Validated @RequestBody ExStudent exStudent) {
        return exStudentService.saveInfo(exStudent);
    }

    /***
     * 学生模块根据id获取数据
     * @param exStudent
     * @return
     */
    @GetMapping("/getByIdInfo")
    public R<ExStudent> getByIdInfo(@Validated ExStudent exStudent) {
        return exStudentService.getByIdInfo(exStudent);
    }


    /***
     * 学生模块根据集合id 批量删除数据
     * @param ids
     * @return R<Void>
     */
    @PostMapping("/removeIdsInfo")
    public R<Void> removeIdsInfo(@RequestBody List<Integer> ids) {
        return exStudentService.removeIdsInfo(ids);
    }
}


网站公告

今日签到

点亮在社区的每一天
去签到