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("Login attempt - StudentID: " + studentId);
|
||
System.out.println("Student found: " + (student != null));
|
||
if (student != null) {
|
||
System.out.println("Stored password: " + student.getPassword());
|
||
System.out.println("Input password: " + password);
|
||
System.out.println("Password match: " + password.equals(student.getPassword()));
|
||
}
|
||
if (student != null && password.equals(student.getPassword())) {
|
||
return student;
|
||
}
|
||
return null;
|
||
}
|
||
}
|