From 86f098f6603d37734e311e5df7f529898a492186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=8E=9A=E8=BE=B0?= Date: Tue, 6 Jun 2023 21:02:32 +0800 Subject: [PATCH 1/3] sixth --- ...\270\232 AttDB\350\257\225\345\215\267.md" | 497 ++++++++++++++++++ 1 file changed, 497 insertions(+) create mode 100644 "53 \345\221\250\345\216\232\350\276\260/20230606 \347\254\254\345\205\255\346\254\241\344\275\234\344\270\232 AttDB\350\257\225\345\215\267.md" diff --git "a/53 \345\221\250\345\216\232\350\276\260/20230606 \347\254\254\345\205\255\346\254\241\344\275\234\344\270\232 AttDB\350\257\225\345\215\267.md" "b/53 \345\221\250\345\216\232\350\276\260/20230606 \347\254\254\345\205\255\346\254\241\344\275\234\344\270\232 AttDB\350\257\225\345\215\267.md" new file mode 100644 index 0000000..7b8e2b0 --- /dev/null +++ "b/53 \345\221\250\345\216\232\350\276\260/20230606 \347\254\254\345\205\255\346\254\241\344\275\234\344\270\232 AttDB\350\257\225\345\215\267.md" @@ -0,0 +1,497 @@ +# 20230606 第六次作业 AttDB试卷 + +## bean包 + +### list类 + +```java +package Bean; + +public class list { + private String sid, sname; + + @Override + public String toString() { + return "list{" + + "sid='" + sid + '\'' + + ", sname='" + sname + '\'' + + '}'; + } + + public String getSid() { + return sid; + } + + public void setSid(String sid) { + this.sid = sid; + } + + public String getSname() { + return sname; + } + + public void setSname(String sname) { + this.sname = sname; + } + + public list() { + } + + public list(String sid, String sname) { + this.sid = sid; + this.sname = sname; + } +} + +``` + +### list2类 + +```java +package Bean; + +public class list2 { + private String aid, time, type, sid, sname; + + public String getSname() { + return sname; + } + + public void setSname(String sname) { + this.sname = sname; + } + + public list2(String aid, String time, String type, String sid, String sname) { + this.aid = aid; + this.time = time; + this.type = type; + this.sid = sid; + this.sname = sname; + } + + public String getAid() { + return aid; + } + + public void setAid(String aid) { + this.aid = aid; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getSid() { + return sid; + } + + public void setSid(String sid) { + this.sid = sid; + } + + @Override + public String toString() { + return "list2{" + + "aid='" + aid + '\'' + + ", time='" + time + '\'' + + ", type='" + type + '\'' + + ", sid='" + sid + '\'' + + '}'; + } + + public list2() { + } + + public list2(String aid, String time, String type, String sid) { + this.aid = aid; + this.time = time; + this.type = type; + this.sid = sid; + } +} + +``` + +## utils包 + +### DBUtil类 + +```java +package Utils; + +import javax.jws.soap.SOAPBinding; +import java.sql.*; + +public class DBUtil { + private static final String Driver = "com.mysql.jdbc.Driver"; + private static final String URL = "jdbc:mysql:///AttDB?useSSL=false&characterEncoding=utf8&useUnicode=true"; + private static final String Username = "root"; + private static final String Paw = "root"; + + static { + try { + Class.forName(Driver); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + System.out.println("注册驱动失败"); + } + } + + public static Connection conn() { + Connection connection = null; + try { + connection = DriverManager.getConnection(URL, Username, Paw); + } catch (SQLException e) { + e.printStackTrace(); + System.out.println("获取连接失败"); + } + return connection; + } + + public static ResultSet query(String sql, Object... keys) { + ResultSet rs = null; + try { + 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) { + System.out.println("查询失败"); + e.printStackTrace(); + } + return rs; + } + + public static int update(String sql, Object... keys) { + int num = 0; + try { + PreparedStatement pst = conn().prepareStatement(sql); + for (int i = 0; i < keys.length; i++) { + pst.setObject((i + 1), keys[i]); + } + num = pst.executeUpdate(); + } catch (SQLException e) { + System.out.println("更新失败"); + e.printStackTrace(); + } + return num; + } +} +``` + +## dao包 + +### list类 + +```java +package Dao; + +import Bean.list2; +import Utils.DBUtil; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +public class list { + private static String sql; + + public static ArrayList getAllList() { + ArrayList list = new ArrayList<>(); + sql = "select * from attence a,student s where a.sid=s.sid order by aid"; + ResultSet rs = DBUtil.query(sql); + try { + while (rs.next()) { + String aid = rs.getString("aid"); + String time = rs.getString("time"); + String type = rs.getString("type"); + String sid = rs.getString("sid"); + String sname = rs.getString("sname"); + list.add(new list2(aid, time, type, sid, sname)); + System.out.println(list); + } + } catch (SQLException e) { + System.out.println("打印失败"); + e.printStackTrace(); + } + return list; + } + + public static ArrayList query() { + ArrayList list = new ArrayList<>(); + sql = "select * from student"; + ResultSet rs = DBUtil.query(sql); + try { + while (rs.next()) { + String sid = rs.getString("sid"); + String sname = rs.getString("sname"); + list.add(new Bean.list(sid, sname)); + System.out.println(list); + } + } catch (SQLException e) { + System.out.println("打印失败"); + e.printStackTrace(); + } + return list; + } + + public static int add(String... keys) { + sql = "insert into attence values (?,?,?,?)"; + int i = DBUtil.update(sql, keys); + return i; + } + + public static int delete(String... keys) { + sql = "delete from attence where aid=?"; + int i = DBUtil.update(sql, keys); + return i; + } +} + +``` + +## servlet包 + +### list类 + +```java +package Servlet; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.util.ArrayList; + +@WebServlet(name = "list", value = "/AttDB/*") +public class list extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String path = request.getPathInfo(); + if (path == null || path.equals("/list")) { + ArrayList list = Dao.list.getAllList(); + request.setAttribute("list", list); + request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request, response); + } else if (path.equals("/add")) { + ArrayList list = Dao.list.query(); + request.setAttribute("list", list); + request.getRequestDispatcher("/WEB-INF/add.jsp").forward(request, response); + } else if (path.equals("/delete")) { + String aid = request.getParameter("aid"); + System.out.println(aid); + int i = Dao.list.delete(aid); + if (i > 0) { +// request.setAttribute("msg", "删除成功"); + response.sendRedirect("/AttDB/list"); + } else { + request.setAttribute("msg", "删除失败"); + request.getRequestDispatcher("/WEB-INF/msg.jsp").forward(request, response); + } + + } + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String path = request.getPathInfo(); + if (path.equals("/save")) { + String sid = request.getParameter("sid"); + String time = request.getParameter("time"); + String type = request.getParameter("type"); + int i = Dao.list.add(null, time, type, sid); + if (i > 0) { + request.setAttribute("msg", "添加成功"); + } else { + request.setAttribute("msg", "添加失败"); + } + request.getRequestDispatcher("/WEB-INF/msg.jsp").forward(request, response); + + } + } +} +``` + +## 网页 + +### 显示页面list + +```jsp +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-06 + Time: 10:57 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 全部信息 + + + +

所有学生信息

+
+ + + +
+ + + + + + + + + + + + + + + + + + + +
考勤编号学生编号学生姓名出勤时间出勤状况操作
${list.aid}${list.sid}${list.sname}${list.time} + 666 + 6 + 66 + + + + +
+ + + +``` + +### 添加页面add + +```jsp +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-06 + Time: 11:34 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 添加 + + + +

添加出勤

+
+ + + + + + + + + + + + + + + + +
学生姓名 + +
考勤时间
考勤状况 + 已到: + 迟到: + 旷课: +
+ +
+
+ + + +``` + +### 提示页面 msg + +```jsp +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-06 + Time: 19:40 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 提示 + + +

${msg}

+ + + + +``` -- Gitee From e30be519667d4d65fe431d230f3c083d8898c394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=8E=9A=E8=BE=B0?= <7964342+zha_cai@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 13:04:54 +0000 Subject: [PATCH 2/3] add README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周厚辰 <7964342+zha_cai@user.noreply.gitee.com> --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..200ff53 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# JSP+Sevrlet网站开发 +6 +#### 介绍 +JSP+Sevrlet网站开发 + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 特技 + +1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md +2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) +3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 +4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 +5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) +6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) -- Gitee From 88abe6ccef2011ed48749f332dca87716ea74b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=8E=9A=E8=BE=B0?= <7964342+zha_cai@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 13:05:15 +0000 Subject: [PATCH 3/3] update README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周厚辰 <7964342+zha_cai@user.noreply.gitee.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 200ff53..b3b1581 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # JSP+Sevrlet网站开发 -6 + #### 介绍 JSP+Sevrlet网站开发 -- Gitee