diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/controller/ClsController.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/controller/ClsController.java index fed0267..71b7b9d 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/controller/ClsController.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/controller/ClsController.java @@ -60,4 +60,9 @@ public class ClsController { return Result.success(cls); } + @DeleteMapping("/class/{id}") + public Result deleteClass(@PathVariable Integer id) { + clsService.deleteById(id); + return Result.success(); + } } diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/controller/StudentController.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/controller/StudentController.java index 365088e..5a35ef6 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/controller/StudentController.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/controller/StudentController.java @@ -1,10 +1,15 @@ package org.dromara.controller; +import com.baomidou.mybatisplus.core.metadata.IPage; import jakarta.annotation.Resource; import org.dromara.common.Result; +import org.dromara.common.core.domain.R; +import org.dromara.common.mybatis.core.page.PageQuery; +import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.domain.Student; import org.dromara.service.IStudentService; import org.dromara.service.impl.StudentService; +import org.springframework.stereotype.Repository; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -52,6 +57,15 @@ public class StudentController { return Result.success(list); } + /** + * 分页查询 + */ + @PostMapping("/selectPage") + public R> selectPage(@RequestBody Student student) { + IPage list = studentService.selectPage(student); + return R.ok(list); + } + /** * 查询单个数据 */ @@ -61,4 +75,5 @@ public class StudentController { return Result.success(student); } + } diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/domain/Student.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/domain/Student.java index eaba563..cd3d487 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/domain/Student.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/domain/Student.java @@ -12,6 +12,10 @@ public class Student { private Integer age; private String sex; private String address; - private String clsId; - private String courseId; + private Integer clsId; + private Integer courseId; + private String clsName; + + private Integer pageNum; + private Integer pageSize; } diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/mapper/ClsMapper.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/mapper/ClsMapper.java index 9ce65bf..383bd3e 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/mapper/ClsMapper.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/mapper/ClsMapper.java @@ -1,19 +1,20 @@ package org.dromara.mapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Select; import org.dromara.domain.Cls; import java.util.List; -public interface ClsMapper { +public interface ClsMapper extends BaseMapper { List selectAll(Cls cls); @Select("select * from cls where id = #{id}") Cls selectById(Integer id); - void insert(Cls cls); + int insert(Cls cls); - void updateById(Cls cls); + int updateById(Cls cls); @Delete("delete from `cls` where id = #{id}") void deleteById(Integer id); diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/mapper/StudentMapper.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/mapper/StudentMapper.java index 50af723..0241830 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/mapper/StudentMapper.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/mapper/StudentMapper.java @@ -1,8 +1,11 @@ package org.dromara.mapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; +import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.domain.Student; import java.util.List; @@ -20,4 +23,11 @@ public interface StudentMapper { void deleteById(Integer id); @Select("select * from student where username = #{username}") Student selectByUsername(String username); + + List selectByClsId(Integer clsId); + + int updateByClsId(@Param("clsId") Integer clsId); + + IPage selectPage(@Param("student") Student student, IPage page); + } diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/IClsService.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/IClsService.java index 0a6d017..f5d7b48 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/IClsService.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/IClsService.java @@ -1,5 +1,6 @@ package org.dromara.service; +import com.baomidou.mybatisplus.extension.service.IService; import org.dromara.domain.Cls; import java.util.List; @@ -10,7 +11,7 @@ import java.util.List; * @author SkySource * @Date: 2025/8/8 9:18 */ -public interface IClsService { +public interface IClsService extends IService { void add(Cls cls); void update(Cls cls); @@ -20,4 +21,5 @@ public interface IClsService { List selectAll(Cls cls); Cls selectById( Integer id); + } diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/IStudentService.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/IStudentService.java index a97213d..ba24beb 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/IStudentService.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/IStudentService.java @@ -1,5 +1,8 @@ package org.dromara.service; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.dromara.common.mybatis.core.page.PageQuery; +import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.domain.Student; import java.util.List; @@ -20,4 +23,7 @@ public interface IStudentService { List selectAll(Student student); Student selectById( Integer id); + + + IPage selectPage(Student student); } diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/impl/ClsService.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/impl/ClsService.java index 67aa4ce..52f3d5e 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/impl/ClsService.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/impl/ClsService.java @@ -1,37 +1,53 @@ package org.dromara.service.impl; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import jakarta.annotation.Resource; import org.dromara.domain.Cls; +import org.dromara.domain.Student; import org.dromara.mapper.ClsMapper; +import org.dromara.mapper.StudentMapper; import org.dromara.service.IClsService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Service -public class ClsService implements IClsService { +public class ClsService extends ServiceImpl implements IClsService { @Resource private ClsMapper clsMapper; + @Resource + private StudentMapper studentMapper; + @Transactional public void add(Cls cls) { clsMapper.insert(cls); } + @Transactional public void update(Cls cls) { clsMapper.updateById(cls); } + @Transactional public void deleteById(Integer id) { + studentMapper.updateByClsId(id); clsMapper.deleteById(id); } + @Transactional public List selectAll(Cls cls) { return clsMapper.selectAll(cls); } - public Cls selectById( Integer id) { + @Transactional(readOnly = true) + public Cls selectById(Integer id) { return clsMapper.selectById(id); } + } diff --git a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/impl/StudentService.java b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/impl/StudentService.java index 0b3ba3b..c8ef9bc 100644 --- a/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/impl/StudentService.java +++ b/ruoyi-modules/ruoyi-student/src/main/java/org/dromara/service/impl/StudentService.java @@ -1,7 +1,10 @@ package org.dromara.service.impl; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import jakarta.annotation.Resource; +import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.domain.Student; import org.dromara.mapper.StudentMapper; import org.dromara.service.IStudentService; @@ -38,5 +41,11 @@ public class StudentService implements IStudentService { public Student selectById( Integer id) { return studentMapper.selectById(id); } + + @Override + public IPage selectPage(Student student) { + IPage page = new Page<>(student.getPageNum(), student.getPageSize()); + return studentMapper.selectPage(student,page); + } } diff --git a/ruoyi-modules/ruoyi-student/src/main/resources/mapper/system/StudentMapper.xml b/ruoyi-modules/ruoyi-student/src/main/resources/mapper/system/StudentMapper.xml index e28b088..8fb3ab2 100644 --- a/ruoyi-modules/ruoyi-student/src/main/resources/mapper/system/StudentMapper.xml +++ b/ruoyi-modules/ruoyi-student/src/main/resources/mapper/system/StudentMapper.xml @@ -12,6 +12,41 @@ order by student.id desc + + + + insert into `student` (username, password, role, name, age, sex, address, cls_id, course_id) values (#{username}, #{password}, #{role}, #{name}, #{age}, #{sex}, #{address}, #{clsId}, #{courseId}) @@ -30,4 +65,10 @@ course_id= #{courseId} where id = #{id} + + + UPDATE student + set cls_id = null + where cls_id = #{clsId} +