显示班级

This commit is contained in:
Asriya
2025-08-09 10:19:05 +08:00
parent c5c67281c5
commit 5433e249bf
10 changed files with 117 additions and 8 deletions

View File

@@ -60,4 +60,9 @@ public class ClsController {
return Result.success(cls); return Result.success(cls);
} }
@DeleteMapping("/class/{id}")
public Result deleteClass(@PathVariable Integer id) {
clsService.deleteById(id);
return Result.success();
}
} }

View File

@@ -1,10 +1,15 @@
package org.dromara.controller; package org.dromara.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.dromara.common.Result; 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.domain.Student;
import org.dromara.service.IStudentService; import org.dromara.service.IStudentService;
import org.dromara.service.impl.StudentService; import org.dromara.service.impl.StudentService;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@@ -52,6 +57,15 @@ public class StudentController {
return Result.success(list); return Result.success(list);
} }
/**
* 分页查询
*/
@PostMapping("/selectPage")
public R<IPage<Student>> selectPage(@RequestBody Student student) {
IPage<Student> list = studentService.selectPage(student);
return R.ok(list);
}
/** /**
* 查询单个数据 * 查询单个数据
*/ */
@@ -61,4 +75,5 @@ public class StudentController {
return Result.success(student); return Result.success(student);
} }
} }

View File

@@ -12,6 +12,10 @@ public class Student {
private Integer age; private Integer age;
private String sex; private String sex;
private String address; private String address;
private String clsId; private Integer clsId;
private String courseId; private Integer courseId;
private String clsName;
private Integer pageNum;
private Integer pageSize;
} }

View File

@@ -1,19 +1,20 @@
package org.dromara.mapper; package org.dromara.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.dromara.domain.Cls; import org.dromara.domain.Cls;
import java.util.List; import java.util.List;
public interface ClsMapper { public interface ClsMapper extends BaseMapper<Cls> {
List<Cls> selectAll(Cls cls); List<Cls> selectAll(Cls cls);
@Select("select * from cls where id = #{id}") @Select("select * from cls where id = #{id}")
Cls selectById(Integer 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}") @Delete("delete from `cls` where id = #{id}")
void deleteById(Integer id); void deleteById(Integer id);

View File

@@ -1,8 +1,11 @@
package org.dromara.mapper; package org.dromara.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.domain.Student; import org.dromara.domain.Student;
import java.util.List; import java.util.List;
@@ -20,4 +23,11 @@ public interface StudentMapper {
void deleteById(Integer id); void deleteById(Integer id);
@Select("select * from student where username = #{username}") @Select("select * from student where username = #{username}")
Student selectByUsername(String username); Student selectByUsername(String username);
List<Student> selectByClsId(Integer clsId);
int updateByClsId(@Param("clsId") Integer clsId);
IPage<Student> selectPage(@Param("student") Student student, IPage<Student> page);
} }

View File

@@ -1,5 +1,6 @@
package org.dromara.service; package org.dromara.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.dromara.domain.Cls; import org.dromara.domain.Cls;
import java.util.List; import java.util.List;
@@ -10,7 +11,7 @@ import java.util.List;
* @author SkySource * @author SkySource
* @Date: 2025/8/8 9:18 * @Date: 2025/8/8 9:18
*/ */
public interface IClsService { public interface IClsService extends IService<Cls> {
void add(Cls cls); void add(Cls cls);
void update(Cls cls); void update(Cls cls);
@@ -20,4 +21,5 @@ public interface IClsService {
List<Cls> selectAll(Cls cls); List<Cls> selectAll(Cls cls);
Cls selectById( Integer id); Cls selectById( Integer id);
} }

View File

@@ -1,5 +1,8 @@
package org.dromara.service; 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 org.dromara.domain.Student;
import java.util.List; import java.util.List;
@@ -20,4 +23,7 @@ public interface IStudentService {
List<Student> selectAll(Student student); List<Student> selectAll(Student student);
Student selectById( Integer id); Student selectById( Integer id);
IPage<Student> selectPage(Student student);
} }

View File

@@ -1,37 +1,53 @@
package org.dromara.service.impl; 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 jakarta.annotation.Resource;
import org.dromara.domain.Cls; import org.dromara.domain.Cls;
import org.dromara.domain.Student;
import org.dromara.mapper.ClsMapper; import org.dromara.mapper.ClsMapper;
import org.dromara.mapper.StudentMapper;
import org.dromara.service.IClsService; import org.dromara.service.IClsService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class ClsService implements IClsService { public class ClsService extends ServiceImpl<ClsMapper, Cls> implements IClsService {
@Resource @Resource
private ClsMapper clsMapper; private ClsMapper clsMapper;
@Resource
private StudentMapper studentMapper;
@Transactional
public void add(Cls cls) { public void add(Cls cls) {
clsMapper.insert(cls); clsMapper.insert(cls);
} }
@Transactional
public void update(Cls cls) { public void update(Cls cls) {
clsMapper.updateById(cls); clsMapper.updateById(cls);
} }
@Transactional
public void deleteById(Integer id) { public void deleteById(Integer id) {
studentMapper.updateByClsId(id);
clsMapper.deleteById(id); clsMapper.deleteById(id);
} }
@Transactional
public List<Cls> selectAll(Cls cls) { public List<Cls> selectAll(Cls cls) {
return clsMapper.selectAll(cls); return clsMapper.selectAll(cls);
} }
public Cls selectById( Integer id) { @Transactional(readOnly = true)
public Cls selectById(Integer id) {
return clsMapper.selectById(id); return clsMapper.selectById(id);
} }
} }

View File

@@ -1,7 +1,10 @@
package org.dromara.service.impl; 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 jakarta.annotation.Resource;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.domain.Student; import org.dromara.domain.Student;
import org.dromara.mapper.StudentMapper; import org.dromara.mapper.StudentMapper;
import org.dromara.service.IStudentService; import org.dromara.service.IStudentService;
@@ -38,5 +41,11 @@ public class StudentService implements IStudentService {
public Student selectById( Integer id) { public Student selectById( Integer id) {
return studentMapper.selectById(id); return studentMapper.selectById(id);
} }
@Override
public IPage<Student> selectPage(Student student) {
IPage<Student> page = new Page<>(student.getPageNum(), student.getPageSize());
return studentMapper.selectPage(student,page);
}
} }

View File

@@ -12,6 +12,41 @@
</where> </where>
order by student.id desc order by student.id desc
</select> </select>
<select id="selectByClsId" resultType="org.dromara.domain.Student">
select *
from student
where id = #{clsId}
order by id desc
</select>
<select id="selectPage" resultType="org.dromara.domain.Student">
select s.id,
s.username,
s.password,
s.role,
s.name,
s.age,
s.sex,
s.address,
s.cls_id,
s.course_id,
s.avatar,
s.create_dept,
s.create_by,
s.create_time,
s.update_by,
s.update_time,
s.remark,
s.del_flag,
c.name as clsName
from student as s
left join cls as c on s.cls_id = c.id
<where>
<if test="student.name != null">s.name like concat('%', #{student.name}, '%')</if>
</where>
order by s.id desc
</select>
<insert id="insert" parameterType="org.dromara.domain.Student"> <insert id="insert" parameterType="org.dromara.domain.Student">
insert into `student` (username, password, role, name, age, sex, address, cls_id, course_id) insert into `student` (username, password, role, name, age, sex, address, cls_id, course_id)
values (#{username}, #{password}, #{role}, #{name}, #{age}, #{sex}, #{address}, #{clsId}, #{courseId}) values (#{username}, #{password}, #{role}, #{name}, #{age}, #{sex}, #{address}, #{clsId}, #{courseId})
@@ -30,4 +65,10 @@
course_id= #{courseId} course_id= #{courseId}
where id = #{id} where id = #{id}
</update> </update>
<update id="updateByClsId">
UPDATE student
set cls_id = null
where cls_id = #{clsId}
</update>
</mapper> </mapper>