环境介绍
Maven(3.6+)、jdk(17+)、tomcat(10+)、MySQL(8.5+)
效果显示



前提准备(私聊提供)
1:BaseDao
2:db.properties
3:js文件(1.12+)
4:jar包的依赖
5:数据库表语句

步骤实现
1:jar包的坐标依赖
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
2:实体类(Student.java)
public class Student {
private Integer sno;
private String sname;
private String sex;
private String birthday;
private String address;
private String phone;
}
3:Dao层接口和实现
3.1:接口定义(StudentDao.java)
public interface StudentDao {
List<Student> find() throws Exception;
int del(int sno) throws Exception;
int add(Student s) throws Exception;
int update(Student s) throws Exception;
Student info(int sno) throws Exception;
}
3.2:接口实现(StudentDaoImpl.java
public class StudentDaoImpl extends BaseDao implements StudentDao {
@Override
public List<Student> find() throws Exception {
List<Student> list = new ArrayList<>();
String sql = "select * from Student ";
ResultSet rs = this.query(null, sql);
while (rs.next()){
Student s = new Student();
s.setSno(rs.getInt("Sno"));
s.setSex(rs.getString("Sex"));
s.setPhone(rs.getString("Phone"));
s.setSname(rs.getString("Sname"));
s.setAddress(rs.getString("Address"));
s.setBirthday(rs.getString("Birthday"));
list.add(s);
}
this.destroy();
return list;
}
@Override
public int del(int sno) throws Exception {
String sql ="delete from Student where sno=? ";
Object [] obj = {
sno};
return this.update(obj,sql);
}
@Override
public int