|
|
|
@ -7,38 +7,70 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
import utils.JDBCUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AdminDaoImpl 实现类,负责对管理员信息进行数据库操作。
|
|
|
|
|
*/
|
|
|
|
|
public class AdminDaoImpl implements AdminDao {
|
|
|
|
|
// 使用 JdbcTemplate 对数据库进行操作
|
|
|
|
|
private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据管理员 ID 和密码查询管理员信息。
|
|
|
|
|
*
|
|
|
|
|
* @param id 管理员 ID
|
|
|
|
|
* @param password 管理员密码
|
|
|
|
|
* @return 如果匹配成功,返回管理员对象;否则返回 null
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Admin findAdminidAndPassword(String id, String password) {
|
|
|
|
|
try {
|
|
|
|
|
// SQL 查询语句
|
|
|
|
|
String sql = "select * from admin where a_id = ? and a_password = ?";
|
|
|
|
|
Admin admin = template.queryForObject(sql,new BeanPropertyRowMapper<Admin>(Admin.class),id,password);
|
|
|
|
|
// 查询并返回结果
|
|
|
|
|
Admin admin = template.queryForObject(sql, new BeanPropertyRowMapper<>(Admin.class), id, password);
|
|
|
|
|
return admin;
|
|
|
|
|
} catch (DataAccessException e) {
|
|
|
|
|
// 数据库访问异常处理
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新管理员密码。
|
|
|
|
|
*
|
|
|
|
|
* @param adminid 管理员 ID
|
|
|
|
|
* @param newpassword 新密码
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void updatePassword(String adminid, String newpassword) {
|
|
|
|
|
try {
|
|
|
|
|
// SQL 更新语句
|
|
|
|
|
String sql = "update admin set a_password=? where a_id=?";
|
|
|
|
|
template.update(sql,newpassword,adminid);
|
|
|
|
|
// 执行更新操作
|
|
|
|
|
template.update(sql, newpassword, adminid);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 异常处理
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据管理员 ID 查询管理员信息。
|
|
|
|
|
*
|
|
|
|
|
* @param id 管理员 ID
|
|
|
|
|
* @return 如果存在,返回管理员对象;否则返回 null
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Admin findAdminById(String id) {
|
|
|
|
|
try {
|
|
|
|
|
// SQL 查询语句
|
|
|
|
|
String sql = "select * from admin where a_id = ?";
|
|
|
|
|
Admin admin = template.queryForObject(sql,new BeanPropertyRowMapper<Admin>(Admin.class),id);
|
|
|
|
|
// 查询并返回结果
|
|
|
|
|
Admin admin = template.queryForObject(sql, new BeanPropertyRowMapper<>(Admin.class), id);
|
|
|
|
|
return admin;
|
|
|
|
|
} catch (DataAccessException e) {
|
|
|
|
|
// 数据库访问异常处理
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|