From a52e0ff94a7cce2780aea88ffbc40cc79b0a7acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E4=BD=B3=E7=82=9C?= <626104790@qq.com> Date: Thu, 8 Jun 2023 12:04:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E5=8B=A4=E8=80=83=E5=AF=9F=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\346\254\241\344\275\234\344\270\232.md" | 421 ++++++++++++++++++ 1 file changed, 421 insertions(+) create mode 100644 "26 \351\231\210\344\275\263\347\202\234/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232.md" diff --git "a/26 \351\231\210\344\275\263\347\202\234/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232.md" "b/26 \351\231\210\344\275\263\347\202\234/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000..29683b9 --- /dev/null +++ "b/26 \351\231\210\344\275\263\347\202\234/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,421 @@ +``` +create database AttDB charset utf8; +use AttDB; +# 表: Student (学生表) +# 字段名 数据类型 默认值 备注和说明 + + +create table Student( + sid int primary key auto_increment,# 主键,自动增长列 + sname varchar(20) not null unique# 唯一,非空 +); +# 表:Attence (考勤表) +# 字段名 数据类型 默认值 备注和说明 +create table Attence ( + aid int primary key auto_increment,#主键,自动增长列 + time varchar(20) not null ,#非空 + type int comment '1:已到;2:迟到;3旷课',#1:已到;2:迟到;3旷课 + sid int ,# 外键 + foreign key (sid) references Student(sid) +); +insert into Student VALUES + (1,'张三'), + (2,'李四'), + (3,'王五'), + (4,'老六'), + (5,'老八'); +insert into Attence values + (1,'2022-05-20 08:20:00',1,1), + (2,'2022-05-23 09:20:00',2,1), + (3,'2022-05-20 08:20:00',2,2), + (4,'2022-05-22 08:20:00',3,2), + (5,'2022-05-23 08:20:00',2,3); + + + + +``` + +``` +package bean; + + + +public class Attence { + + private int aid; + + private String time; + + private int type; + + private int sid; + + private String sname; + + + + public Attence(int aid, String time, int type, int sid, String sname) { + +​ this.aid = aid; + +​ this.time = time; + +​ this.type = type; + +​ this.sid = sid; + +​ this.sname = sname; + + } + + + + public Attence() { + + } + + + + public int getAid() { + +​ return aid; + + } + + + + public void setAid(int aid) { + +​ this.aid = aid; + + } + + + + public String getTime() { + +​ return time; + + } + + + + public void setTime(String time) { + +​ this.time = time; + + } + + + + public int getType() { + +​ return type; + + } + + + + public void setType(int type) { + +​ this.type = type; + + } + + + + public int getSid() { + +​ return sid; + + } + + + + public void setSid(int sid) { + +​ this.sid = sid; + + } + + + + public String getSname() { + +​ return sname; + + } + + + + public void setSname(String sname) { + +​ this.sname = sname; + + } + + + + @Override + + public String toString() { + +​ return "Attence{" + + +​ "aid=" + aid + + +​ ", time='" + time + '\'' + + +​ ", type=" + type + + +​ ", sid=" + sid + + +​ ", sname='" + sname + '\'' + + +​ '}'; + + } + +} + + + +package bean; + + + +public class Student { + + private int sid; + + private String sname; + + + + @Override + + public String toString() { + +​ return "Student{" + + +​ "sid=" + sid + + +​ ", sname='" + sname + '\'' + + +​ '}'; + + } + + + + public int getSid() { + +​ return sid; + + } + + + + public void setSid(int sid) { + +​ this.sid = sid; + + } + + + + public String getSname() { + +​ return sname; + + } + + + + public void setSname(String sname) { + +​ this.sname = sname; + + } + + + + public Student() { + + } + + + + public Student(int sid, String sname) { + +​ this.sid = sid; + +​ this.sname = sname; + + } + +} + + +``` + +``` +package utils; + + + +import java.sql.*; + + + +public class DBUtil { + + static String url="jdbc:mysql///AttDB?useSSL=false&characterEncoding=utf8"; + + static String user="root"; + + static String pwd="root"; + + static { + +​ try { + +​ Class.forName("com.mysql.jdbc.Driver"); + +​ } catch (ClassNotFoundException e) { + +​ e.printStackTrace(); + +​ } + + } + + public static Connection getConn() throws SQLException { + +​ Connection conn = DriverManager.getConnection(url, user, pwd); + +​ return conn; + + } + + public static ResultSet query(String sql,Object... keys){ + +​ ResultSet rs = null; + +​ try { + +​ Connection conn = getConn(); + +​ PreparedStatement pst = conn.prepareStatement(sql); + +​ for (int i = 0; i < keys.length; i++) { + +​ pst.setObject((i+1),keys[i]); + +​ } + +​ rs = pst.executeQuery(); + +​ } catch (SQLException e) { + +​ throw new RuntimeException(e); + +​ } + +​ return rs; + + } + +} +``` + +``` +package servlet; + +import utils.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +@WebServlet("/List") +public class ListServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + String sql ="select * from attence a,student s where a.sid=s.sid"; + ResultSet res = DBUtil.query(sql); + ArrayList list = new ArrayList<>(); + try { + while (res.next()){ + int aid = res.getInt("aid"); + String time = res.getString("time"); + int type = res.getInt("type"); + int sid = res.getInt("sid"); + String sname = res.getString("sname"); + Attence attence = new Attence(aid, time, type, sid, sname); + list.add(attence); + } + } catch (SQLException e) { + e.printStackTrace(); + } + request.setAttribute("list",list); + request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} +``` + +``` +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 考勤 + + +添加 + + + + + + + + + + + + + + + + + + + +
考勤编号学生编号学生姓名出勤时间出勤状况
${a.aid}${a.sid}${a.sname}${a.time} + + 已到 + + + 迟到 + + + 旷课 + +
+ + +``` + -- Gitee