|
|
|
@ -0,0 +1,117 @@
|
|
|
|
|
package com.itheima.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.itheima.dao.StudentDao; // 导入StudentDao接口,用于数据访问操作
|
|
|
|
|
import com.itheima.po.PageInfo; // 导入PageInfo类,用于封装分页信息
|
|
|
|
|
import com.itheima.po.Student; // 导入Student类,用于表示学生对象
|
|
|
|
|
import com.itheima.service.StudentService; // 导入StudentService接口,该类实现该接口
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 导入自动注入的注解
|
|
|
|
|
import org.springframework.stereotype.Service; // 导入Service注解,标识这是一个Service类
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; // 导入事务管理注解
|
|
|
|
|
|
|
|
|
|
import java.util.List; // 导入List类,用于存储多个学生对象
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户Service接口实现类
|
|
|
|
|
*/
|
|
|
|
|
@Service("studentService") // 标注该类为一个Spring管理的服务组件,名称为studentService
|
|
|
|
|
@Transactional // 启用事务管理,确保该类中的数据库操作要么全部成功,要么全部回滚,保证数据一致性和完整性
|
|
|
|
|
public class StudentServiceImpl implements StudentService {
|
|
|
|
|
|
|
|
|
|
// 自动注入StudentDao,DAO层用于与数据库交互
|
|
|
|
|
@Autowired
|
|
|
|
|
private StudentDao studentDao;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询学生信息
|
|
|
|
|
* @param s_name 学生姓名
|
|
|
|
|
* @param s_studentid 学生ID
|
|
|
|
|
* @param s_classid 班级ID
|
|
|
|
|
* @param s_classname 班级名称
|
|
|
|
|
* @param pageIndex 当前页码
|
|
|
|
|
* @param pageSize 每页显示的记录数
|
|
|
|
|
* @return 返回分页信息(PageInfo)
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public PageInfo<Student> findPageInfo(String s_name, Integer s_studentid, Integer s_classid,
|
|
|
|
|
String s_classname, Integer pageIndex, Integer pageSize) {
|
|
|
|
|
// 创建PageInfo对象,用于封装分页信息
|
|
|
|
|
PageInfo<Student> pi = new PageInfo<Student>();
|
|
|
|
|
pi.setPageIndex(pageIndex); // 设置当前页码
|
|
|
|
|
pi.setPageSize(pageSize); // 设置每页显示的记录数
|
|
|
|
|
|
|
|
|
|
// 获取符合条件的总记录数
|
|
|
|
|
Integer totalCount = studentDao.totalCount(s_name, s_studentid, s_classid, s_classname);
|
|
|
|
|
|
|
|
|
|
// 如果总记录数大于0,进行分页查询
|
|
|
|
|
if (totalCount > 0) {
|
|
|
|
|
pi.setTotalCount(totalCount); // 设置总记录数
|
|
|
|
|
|
|
|
|
|
// 根据页码和每页大小计算出查询的起始位置,并获取当前页的学生列表
|
|
|
|
|
// currentPage = (pageIndex - 1) * pageSize,当前页码减去1,乘以每页记录数,得到查询的起始位置
|
|
|
|
|
List<Student> studentList = studentDao.getStudentList(
|
|
|
|
|
s_name, s_studentid, s_classid, s_classname,
|
|
|
|
|
(pi.getPageIndex() - 1) * pi.getPageSize(), pi.getPageSize()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
pi.setList(studentList); // 设置当前页的学生列表
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pi; // 返回封装了分页信息的PageInfo对象
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取所有学生信息
|
|
|
|
|
* @return 返回所有学生的列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<Student> getAll() {
|
|
|
|
|
// 调用DAO层的getAll方法获取所有学生信息
|
|
|
|
|
List<Student> studentList = studentDao.getAll();
|
|
|
|
|
return studentList; // 返回所有学生的列表
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除指定ID的学生信息
|
|
|
|
|
* @param s_id 学生ID
|
|
|
|
|
* @return 返回受影响的行数,通常为1表示删除成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int deleteStudent(Integer s_id) {
|
|
|
|
|
// 调用DAO层的deleteStudent方法删除指定ID的学生记录
|
|
|
|
|
return studentDao.deleteStudent(s_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加学生信息
|
|
|
|
|
* @param student 学生对象,包含要添加的学生信息
|
|
|
|
|
* @return 返回受影响的行数,通常为1表示插入成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int addStudent(Student student) {
|
|
|
|
|
// 调用DAO层的addStudent方法添加新的学生记录
|
|
|
|
|
return studentDao.addStudent(student);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新学生信息
|
|
|
|
|
* @param student 学生对象,包含要更新的学生信息
|
|
|
|
|
* @return 返回受影响的行数,通常为1表示更新成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int updateStudent(Student student) {
|
|
|
|
|
// 调用DAO层的updateStudent方法更新指定学生的信息
|
|
|
|
|
return studentDao.updateStudent(student);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据学生ID查找学生信息
|
|
|
|
|
* @param s_id 学生ID
|
|
|
|
|
* @return 返回对应ID的学生信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Student findStudentById(Integer s_id) {
|
|
|
|
|
// 调用DAO层的findStudentById方法根据学生ID查询学生信息
|
|
|
|
|
Student s = studentDao.findStudentById(s_id);
|
|
|
|
|
return s; // 返回查询到的学生对象
|
|
|
|
|
}
|
|
|
|
|
}
|