You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<<<<<<< HEAD
package service;
import entity.User;
import java.util.HashMap;
import java.util.Map;
/**
用户服务类
负责用户认证和用户数据管理
使用内存存储用户信息(实际项目中应该使用数据库)
*/
public class UserService {
private final Map<String, User> users = new HashMap<>(); // 用户名到用户的映射
/**
构造函数,初始化预定义的用户数据
*/
public UserService() {
initializeUsers();
}
/**
初始化预定义的用户账户
包括小学、初中、高中各三个账户
*/
private void initializeUsers() {
// 小学账户
users.put("张三1", new User("张三1", "123", "小学"));
users.put("张三2", new User("张三2", "123", "小学"));
users.put("张三3", new User("张三3", "123", "小学"));
// 初中账户
users.put("李四1", new User("李四1", "123", "初中"));
users.put("李四2", new User("李四2", "123", "初中"));
users.put("李四3", new User("李四3", "123", "初中"));
// 高中账户
users.put("王五1", new User("王五1", "123", "高中"));
users.put("王五2", new User("王五2", "123", "高中"));
users.put("王五3", new User("王五3", "123", "高中"));
}
/**
用户认证方法
@param username 用户名
@param password 密码
@return 认证成功的用户对象失败返回null
*/
public User authenticate(String username, String password) {
User user = users.get(username);
// 检查用户是否存在且密码匹配
if (user != null && user.getPassword().equals(password)) {
return user;
}
return null;
}
}
=======
package main.java.service;
public class UserService {
}
>>>>>>> 93d8b771666e4fb2ee7477c19dcf6f4fb1eec045