pull/1/head
lxb 8 months ago
parent 9728b0799e
commit 5f0eac6294

@ -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;
}

Loading…
Cancel
Save