赞
踩
=====================================================================
=====================================================================
package com.sjsq.dao;
import com.sjsq.vo.Admin;
/**
@author shuijianshiqing
@date 2021/5/1 9:46
*/
public interface AdminDao {
/**
用户登录
@param admin
@return
*/
public Admin login(Admin admin);
}
package com.sjsq.dao.impl;
import com.sjsq.dao.AdminDao;
import com.sjsq.utils.DBUtil;
import com.sjsq.vo.Admin;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
@author shuijianshiqing
@date 2021/5/1 9:49
*/
public class AdminDaoImpl implements AdminDao {
/**
用户登录
@param admin
@return
*/
@Override
public Admin login(Admin admin) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.获取数据库连接
con = DBUtil.getConnection();
// 2.写sql
String sql = “select * from admin where username = ? and password = ?”;
// 3.预编译
ps = con.prepareStatement(sql);
// 4.设置值
ps.setObject(1,admin.getUsername());
ps.setObject(2,admin.getPassword());
rs = ps.executeQuery();
Admin adminLogin = null;
if(rs.next()){
adminLogin = new Admin();
// 从数据库中获取值到实体类的setter方法中
adminLogin.setUsername(rs.getString(“username”));
adminLogin.setPassword(rs.getString(“password”));
// 返回的是你查询出来的完整的对象
return adminLogin;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally {
// 关闭资源,避免出现异常
DBUtil.close(con,ps,rs);
}
return null;
}
}
package com.sjsq.dao;
import com.sjsq.vo.Student;
import java.util.List;
/**
@author shuijianshiqing
@date 2021/4/30 7:52
学生信息接口
*/
public interface StudentDao {
/**
查询学生信息
@param sql
@param arr
@return
*/
public List selectAll(String sql, Object[] arr);
/**
根据学号进行查询
@param id
@return
*/
public Student selectStudent(Integer id);
/**
新增学生信息
@param student
@return
*/
public boolean addStudent(Student student);
/**
修改学生信息
@param student
@return
*/
public boolean updateStudent(Student student);
/**
删除学生信息
@param id
@return
*/
public boolean deleteStudent(Integer id);
}
package com.sjsq.service;
import com.sjsq.vo.Admin;
/**
@author shuijianshiqing
@date 2021/5/1 11:13
*/
public interface AdminService {
/**
用户登录
@param admin
@return
*/
public Admin login(Admin admin);
}
package com.sjsq.service.impl;
import com.sjsq.dao.AdminDao;
import com.sjsq.dao.impl.AdminDaoImpl;
import com.sjsq.service.AdminService;
import com.sjsq.vo.Admin;
/**
@author shuijianshiqing
@date 2021/5/1 11:13
*/
public class AdminServiceImpl implements AdminService {
private AdminDao adminDao = new AdminDaoImpl();
@Override
public Admin login(Admin admin) {
return adminDao.login(admin);
}
}
package com.sjsq.service;
import com.sjsq.vo.Student;
import java.util.List;
/**
@author shuijianshiqing
@date 2021/5/1 8:26
*/
public interface StudentService {
/**
查询学生信息
@param student
@return
*/
public List selectAll(Student student);
/**
根据学号进行查询
@param id
@return
*/
public Student selectStudent(Integer id);
/**
新增学生信息
@param student
@return
*/
public boolean addStudent(Student student);
/**
修改学生信息
@param student
@return
*/
public boolean updateStudent(Student student);
/**
删除学生信息
@param id
@return
*/
public boolean deleteStudent(Integer id);
}
package com.sjsq.service.impl;
import com.sjsq.dao.StudentDao;
import com.sjsq.dao.impl.StudentDaoImpl;
import com.sjsq.service.StudentService;
import com.sjsq.vo.Student;
import java.util.ArrayList;
import java.util.List;
/**
@author shuijianshiqing
@date 2021/5/1 8:26
*/
public class StudentServiceImpl implements StudentService {
private StudentDao studentDao = new StudentDaoImpl();
@Override
public List selectAll(Student student) {
StringBuffer sql = new StringBuffer("select * from student where 1 = 1 ");
List list = new ArrayList();
if(student != null){
// 根据id来查找对应的学生信息
if(student.getId() != null && student.getId() != 0){
sql.append(" and id = ?");
list.add(student.getId());
}
}
return studentDao.selectAll(sql.toString(),list.toArray());
}
@Override
public Student selectStudent(Integer id) {
return studentDao.selectStudent(id);
}
@Override
public boolean addStudent(Student student) {
return studentDao.addStudent(student);
}
@Override
public boolean updateStudent(Student student) {
return studentDao.updateStudent(student);
}
@Override
public boolean deleteStudent(Integer id) {
return studentDao.deleteStudent(id);
}
}
<%@ page contentType=“text/html;charset=UTF-8” language=“java” pageEncoding=“UTF-8” %>
<%
// 获取绝对路径路径 ,开发项目一定要使用绝对路径,不然肯定出错
String path = request.getContextPath();
String basePath = request.getScheme() + “
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。