From 40eb56caf5dca4ba7cdcd1a9bef90c58f5fc7d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E9=94=90?= <2570878950@qq.com> Date: Tue, 6 Jun 2023 23:52:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=88=91=E7=9A=84=E7=AC=AC=E5=85=AD?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230606 \344\275\234\344\270\232.md" | 475 ++++++++++++++++++ 1 file changed, 475 insertions(+) create mode 100644 "20 \345\206\257\351\224\220/20230606 \344\275\234\344\270\232.md" diff --git "a/20 \345\206\257\351\224\220/20230606 \344\275\234\344\270\232.md" "b/20 \345\206\257\351\224\220/20230606 \344\275\234\344\270\232.md" new file mode 100644 index 0000000..e76a9c6 --- /dev/null +++ "b/20 \345\206\257\351\224\220/20230606 \344\275\234\344\270\232.md" @@ -0,0 +1,475 @@ +```java +package bean; + +public class attence { + private int id; + private String time; + private int type; + private int sid; + private String stuName; + private String name; + private int aid; + + @Override + public String toString() { + return "attence{" + + "id=" + id + + ", time='" + time + '\'' + + ", type=" + type + + ", sid=" + sid + + ", stuName='" + stuName + '\'' + + ", name='" + name + '\'' + + ", aid=" + aid + + '}'; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + 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 getStuName() { + return stuName; + } + + public void setStuName(String stuName) { + this.stuName = stuName; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAid() { + return aid; + } + + public void setAid(int aid) { + this.aid = aid; + } + + public attence(int id, String time, int type, int sid, String stuName, String name, int aid) { + this.id = id; + this.time = time; + this.type = type; + this.sid = sid; + this.stuName = stuName; + this.name = name; + this.aid = aid; + } + + public attence() { + } +} + +``` + +```java +package bean; + +public class student { + private int id; + private String name; + + @Override + public String toString() { + return "student{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public student(int id, String name) { + this.id = id; + this.name = name; + } + + public student() { + } +} + +``` + +```java +package servlet; + +import bean.student; +import util.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.*; +import java.util.ArrayList; + +@WebServlet("/add") +public class add extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String sql="select * from student"; + ArrayList list = new ArrayList<>(); + Connection conn = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + conn = DBUtil.getConn(); + pst = conn.prepareStatement(sql); + rs = pst.executeQuery(); + while (rs.next()){ + int id = rs.getInt(1); + String name = rs.getString(2); + student student = new student(id, name); + list.add(student); + + + } + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + DBUtil.close(conn,pst,rs); + } + + + request.setAttribute("list",list); + + + request.getRequestDispatcher("/WEB-INF/from.jsp").forward(request,response); + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} + +``` + +```java +package servlet; + +import bean.attence; +import util.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +@WebServlet("/list") +public class list extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String sql="select * from student s,attence a where s.sid=a.sid"; + ArrayList list = new ArrayList<>(); + Connection conn = null; + PreparedStatement pst = null; + ResultSet rs = null; + try { + conn = DBUtil.getConn(); + pst = conn.prepareStatement(sql); + rs = pst.executeQuery(); + while (rs.next()){ + int id = rs.getInt(1); + String name = rs.getString(2); + int aid = rs.getInt(3); + String time = rs.getString(4); + int type = rs.getInt(5); + String sutName = rs.getString(6); + attence att = new attence(id,time,type,0,sutName,name,aid); + list.add(att); + + + } + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + DBUtil.close(conn,pst,rs); + } + + request.setAttribute("list",list); + request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response); + + + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} + +``` + +```java +package servlet; + +import util.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +@WebServlet("/save") +public class save extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf-8"); + int sid = Integer.parseInt(request.getParameter("sid")); + String time = request.getParameter("time"); + int type = Integer.parseInt(request.getParameter("type")); + + String sql="insert into attence values (?,?,?,?)"; + + int i = 0; + Connection conn = null; + PreparedStatement pst = null; + try { + conn = DBUtil.getConn(); + pst = conn.prepareStatement(sql); + pst.setInt(1,0); + pst.setString(2,time); + pst.setInt(3,type); + pst.setInt(4,sid); + i = pst.executeUpdate(); + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + DBUtil.close(conn,pst,null); + } + if (i>0){ + response.sendRedirect("/list"); + }else { + request.setAttribute("msg","添加失败"); + request.getRequestDispatcher("/WEB-INF/msg.jsp").forward(request,response); + } + + + } +} +``` + +```java +package util; + +import java.sql.*; + +public class DBUtil { + static String url = "jdbc:mysql:///attdb?useSSL=false&useUnicode=true&characterEncoding=utf8"; + static String user = "root"; + static String pwd = "root"; + static { + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + + public static Connection getConn() throws SQLException { + Connection conn = DriverManager.getConnection(url, user, pwd); + return conn; + } + + public static void close(Connection conn, PreparedStatement pst, ResultSet rs) { + try { + if (rs != null) { + rs.close(); + } + if (pst != null) { + pst.close(); + } + if (conn != null) { + conn.close(); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + + } +} +``` + +```jsp +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-05 + Time: 10:17 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + + +
+ + + + + + + + + + + + + + + + + + + +
学生姓名
考勤时间
考勤状况 +
+ + + + + + +
+
+ +
+ + + + +``` + +```jsp +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-05 + Time: 09:41 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + + + + + + + + + + + + + + + + + + + + + + +
考勤编号学生编号学生姓名出勤时间出勤状况
${attence.aid}${attence.id}${attence.name}${attence.time}${attence.type}
+ + + +``` + +```jsp +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 提醒 + + +${msg} +
+返回列表 + + +``` + -- Gitee From f8c0ed77ce8acc1eeef8749fd888cc279a20499e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E9=94=90?= <2570878950@qq.com> Date: Fri, 9 Jun 2023 22:26:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=88=91=E7=9A=84=E7=AC=AC=E4=B8=83?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230609 \344\275\234\344\270\232.md" | 443 ++++++++++++++++++ 1 file changed, 443 insertions(+) create mode 100644 "20 \345\206\257\351\224\220/20230609 \344\275\234\344\270\232.md" diff --git "a/20 \345\206\257\351\224\220/20230609 \344\275\234\344\270\232.md" "b/20 \345\206\257\351\224\220/20230609 \344\275\234\344\270\232.md" new file mode 100644 index 0000000..b991224 --- /dev/null +++ "b/20 \345\206\257\351\224\220/20230609 \344\275\234\344\270\232.md" @@ -0,0 +1,443 @@ +```JAVA +package gongju; + +import java.sql.*; + +public class DBUtil { + static String url="jdbc:mysql:///test?characterEncoding=utf8"; + static String user = "root"; + static String password = "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,password); + return conn; +} +public static ResultSet query(String sql , Object...tj) throws SQLException { + Connection conn = getconn(); + PreparedStatement pre = conn.prepareStatement(sql); + ResultSet re = null; + for (int i = 0; i < tj.length; i++) { + pre.setObject((i+1),tj[i]); + } + re = pre.executeQuery(); + return re; +} + public static int update(String sql , Object...tj) throws SQLException { + Connection conn = getconn(); + PreparedStatement pre = conn.prepareStatement(sql); + int re = 0; + for (int i = 0; i < tj.length; i++) { + pre.setObject((i+1),tj[i]); + } + re = pre.executeUpdate(); + return re; + } + public static void close(ResultSet re , PreparedStatement pre , Connection conn) throws SQLException { + if (re!=null){ + re.close(); + } + if (pre!=null){ + pre.close(); + } + if (conn!=null){ + conn.close(); + } + } +} +``` + +```JAVA +package pickaging; + +public class HouseInfo { + private int id; + private String mode; + private double rent; + private String cont; + private String method; + private int house; + private String addr; + + public HouseInfo() { + } + + public HouseInfo(int id, String mode, double rent, String cont, String method, int house, String addr) { + this.id = id; + this.mode = mode; + this.rent = rent; + this.cont = cont; + this.method = method; + this.house = house; + this.addr = addr; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getMode() { + return mode; + } + + public void setMode(String mode) { + this.mode = mode; + } + + public double getRent() { + return rent; + } + + public void setRent(double rent) { + this.rent = rent; + } + + public String getCont() { + return cont; + } + + public void setCont(String cont) { + this.cont = cont; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public int getHouse() { + return house; + } + + public void setHouse(int house) { + this.house = house; + } + + public String getAddr() { + return addr; + } + + public void setAddr(String addr) { + this.addr = addr; + } + + @Override + public String toString() { + return "HouseInfo{" + + "id=" + id + + ", mode='" + mode + '\'' + + ", rent=" + rent + + ", cont='" + cont + '\'' + + ", method='" + method + '\'' + + ", house=" + house + + ", addr='" + addr + '\'' + + '}'; + } +} +``` + +```JAVA +package pickaging; + +public class HouseType { + private int id; + private String type; + + public HouseType() { + } + + public HouseType(int id, String type) { + this.id = id; + this.type = type; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "HouseType{" + + "id=" + id + + ", type='" + type + '\'' + + '}'; + } +} +``` + +```JAVA +package yingyong; + +import gongju.DBUtil; +import pickaging.HouseInfo; +import pickaging.HouseType; + +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("/add") +public class Add extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf8"); + response.setContentType("text/html;charset=utf8"); + String sql = "select * from house_type;"; + try { + ResultSet re = DBUtil.query(sql); + ArrayList list = new ArrayList<>(); + while (re.next()){ + int id = re.getInt("id"); + String type = re.getString("type"); + HouseType ht = new HouseType(id, type); + list.add(ht); + } + request.setAttribute("list",list); + request.getRequestDispatcher("WEB-INF/add.jsp").forward(request,response); + } catch (SQLException e) { + e.printStackTrace(); + } + + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} +``` + +```JAVA +package yingyong; + +import gongju.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.SQLException; + +@WebServlet("/insert") +public class Insert extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doPost(request,response); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf8"); + response.setContentType("text/html;charset=utf8"); + String id = request.getParameter("id"); + String mode = request.getParameter("mode"); + String rent = request.getParameter("rent"); + String cont = request.getParameter("cont"); + String method = request.getParameter("method"); + int house = Integer.parseInt(request.getParameter("type")); + String addr = request.getParameter("addr"); + String sql = "insert into house_info values (0,?,?,?,?,?,?)"; + int i = 0; + try { + i = DBUtil.update(sql,mode, rent, cont, method, house, addr); + } catch (SQLException e) { + throw new RuntimeException(e); + } + if (i>0){ + response.getWriter().write(""); +// resp.getWriter().write(""); + }else { + response.getWriter().write("添加失败"); + } + } +} +``` + +```JAVA +package yingyong; + +import gongju.DBUtil; +import pickaging.HouseInfo; + +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("/select") +public class Select extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf8"); + response.setContentType("text/html;charset=utf8"); + String sql = "select * from house_info i left join house_type t on i.house_type_id = t.id"; + try { + ResultSet re = DBUtil.query(sql); + ArrayList list = new ArrayList<>(); + while (re.next()){ + int id = re.getInt(1); + int typeid = re.getInt(6); + String mode = re.getString(2); + double rent = re.getDouble(3); + String cont = re.getString(4); + String depo = re.getString(5); + String addr = re.getString(7); + int tid = re.getInt(8); + String type = re.getString(9); + HouseInfo hi = new HouseInfo(id, mode, rent, cont, depo, tid, addr); + list.add(hi); + } + request.setAttribute("list",list); + request.getRequestDispatcher("WEB-INF/list.jsp").forward(request,response); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} +``` + +```JSP +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-07 + Time: 11:22 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
租赁方式
租金
联系人
押金方式
房屋类型 + +
详细地址
+
+ + +``` + +```JSP +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-07 + Time: 10:59 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + +
+ +
+ + + + + + + + + + + + + + + + + + + + +
编号租赁方式租金(元)联系人押金方式房屋类型详细地址
${fz.id}${fz.mode}${fz.rent}${fz.cont}${fz.method}${fz.house}${fz.addr}
+ + +``` + + + -- Gitee