43 lines
1.2 KiB
Java
43 lines
1.2 KiB
Java
package service;
|
||
|
||
import dao.DAOFactory;
|
||
import dao.StudentDAO;
|
||
import model.Student;
|
||
|
||
/**
|
||
* 学生信息服务类
|
||
*/
|
||
public class StudentService {
|
||
private final StudentDAO studentDAO = DAOFactory.getStudentDAO();
|
||
|
||
/**
|
||
* 根据ID查询学生
|
||
* @param id 学生ID
|
||
* @return 学生信息
|
||
*/
|
||
public Student getStudentById(int id) {
|
||
return studentDAO.findById(id);
|
||
}
|
||
|
||
/**
|
||
* 学生登录
|
||
* @param studentId 学号
|
||
* @param password 密码
|
||
* @return 登录成功返回学生信息,失败返回null
|
||
*/
|
||
public Student login(String studentId, String password) {
|
||
Student student = studentDAO.findByStudentId(studentId);
|
||
System.out.println("尝试登录 - 学号: " + studentId);
|
||
System.out.println("找到学生:" + (student != null));
|
||
if (student != null) {
|
||
System.out.println("存储密码:" + student.getPassword());
|
||
System.out.println("输入密码:" + password);
|
||
System.out.println("密码匹配:" + password.equals(student.getPassword()));
|
||
}
|
||
if (student != null && password.equals(student.getPassword())) {
|
||
return student;
|
||
}
|
||
return null;
|
||
}
|
||
}
|