From 03b42c564b1a188ed3fe920de15ef764f53a5283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E5=B0=8F=E9=83=AD?= <2966479092@qq.com> Date: Mon, 12 Jun 2023 19:35:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AC=AC=E4=B8=83=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\347\220\206\347\263\273\347\273\237.md" | 281 ++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 "47 \346\250\212\345\260\217\351\203\255/20230609 \345\221\230\345\267\245\347\256\241\347\220\206\347\263\273\347\273\237.md" diff --git "a/47 \346\250\212\345\260\217\351\203\255/20230609 \345\221\230\345\267\245\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/47 \346\250\212\345\260\217\351\203\255/20230609 \345\221\230\345\267\245\347\256\241\347\220\206\347\263\273\347\273\237.md" new file mode 100644 index 0000000..3c96e1a --- /dev/null +++ "b/47 \346\250\212\345\260\217\351\203\255/20230609 \345\221\230\345\267\245\347\256\241\347\220\206\347\263\273\347\273\237.md" @@ -0,0 +1,281 @@ +# 员工管理系统 + +`mysql +create database CompanyManager charset utf8; +use CompanyManager; +create table Dept +( + DeptID int primary key auto_increment, #部门编号 主键,自动增长列 + DeptName varchar(20) not null #部门名称 不允许为空 +); +create table Emp +( + EmpID int primary key auto_increment, # 员工编号主键,自动增长列 + EmpName varchar(20) not null, # 员工姓名 不允许为空 + Sex char(2) not null, # 性别 不允许为空 + Age int not null, # 员工年龄 不允许为空 + Tel varchar(20) not null unique, # 联系电话 不允许为空(唯一约束) + PassWord varchar(12) not null, # 密码 不允许为空 + DeptID int, # 部门编号 外键,关联部门表DeptID字段 + foreign key (DeptID) references Dept (DeptID) +); +insert into dept +values (null, '开发部'), + (null, '测试部'), + (null, 'UI部'); +insert into emp +values (null, '飞影铠甲', '男', 21, '10759872563', '188', 1), + (null, '焰之拿瓦', '女', 21, '10759874563', '186', 2), + (null, '金刚铠甲', '男', 21, '10752344563', '182', 3); +select * from dept d , emp e where d.DeptID=e.DeptID; +select * from dept d,emp e where d.deptId=e.deptId; +```java + +```java +package Dept; + +public class bean { + int deptId; + String deptName; + + public int getDeptId() { + return deptId; + } + + public void setDeptId(int deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public bean() { + } + + public bean(int deptId, String deptName) { + this.deptId = deptId; + this.deptName = deptName; + } +} +package Dept; + +public class Emp { + int empId; + String empName; + String sex; + int age; + String tel; + String passWord; + int deptId; + String deptName; + + public int getEmpId() { + return empId; + } + + public void setEmpId(int empId) { + this.empId = empId; + } + + public String getEmpName() { + return empName; + } + + public void setEmpName(String empName) { + this.empName = empName; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getPassWord() { + return passWord; + } + + public void setPassWord(String passWord) { + this.passWord = passWord; + } + + public int getDeptId() { + return deptId; + } + + public void setDeptId(int deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public Emp() { + } + + public Emp(int empId, String empName, String sex, int age, String tel, String passWord, int deptId, String deptName) { + this.empId = empId; + this.empName = empName; + this.sex = sex; + this.age = age; + this.tel = tel; + this.passWord = passWord; + this.deptId = deptId; + this.deptName = deptName; + } +} +package servlet; + +import Dept.Emp; +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 { + request.setCharacterEncoding("utf-8"); +// String username = request.getParameter("username"); + String sql="select * from dept d,emp e where d.deptID=e.deptID"; + ResultSet rs = DBUtil.query(sql); + ArrayList list = new ArrayList(); + try { + while (rs.next()){ + int deptId=rs.getInt(1); + String empName=rs.getString(2); + String empId = rs.getString(3); + String deptname=rs.getString(4); + String sex=rs.getString(5); + int age = rs.getInt(6); + String tel=rs.getString(7); + String password= rs.getString(8); + Emp emp = new Emp(deptId,empName,sex,age,tel,password,deptId,deptname); + list.add(emp); + } + } 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 { + + } +} +package servlet; + +import Dept.Emp; +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("/search") +public class SearchServlet 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"); + String username = request.getParameter("username"); + String sql="select * from dept d,emp e where d.deptID=e.deptID and empname like ?"; + ResultSet rs = DBUtil.query(sql,"%"+username+"%"); + ArrayList list = new ArrayList(); + try { + while (rs.next()){ + int deptId=rs.getInt(1); + String empName=rs.getString(2); + String empId = rs.getString(3); + String deptname=rs.getString(4); + String sex=rs.getString(5); + int age = rs.getInt(6); + String tel=rs.getString(7); + String password= rs.getString(8); + Emp emp = new Emp(deptId,empName,sex,age,tel,password,deptId,deptname); + list.add(emp); + } + } catch (SQLException e) { + e.printStackTrace(); + } + request.setAttribute("list",list); + request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response); + } + } +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 员工管理 + + +
+ 姓名: +
+ + + + + + + + + + + + + + + + + + + +
编号姓名性别年龄电话所属部门
${emp.empId}${emp.deptName}${emp.sex}${emp.age}${emp.tel}${emp.empName}
+ + +``` -- Gitee From 0fdea69e83b65ede0304a1287eb6f723a2e497c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8A=E5=B0=8F=E9=83=AD?= <2966479092@qq.com> Date: Mon, 12 Jun 2023 19:43:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=AC=AC=E5=85=AB=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\347\220\206\347\263\273\347\273\237.md" | 522 ++++++++++++++++++ 1 file changed, 522 insertions(+) create mode 100644 "47 \346\250\212\345\260\217\351\203\255/20230612 \346\210\277\345\261\213\347\256\241\347\220\206\347\263\273\347\273\237.md" diff --git "a/47 \346\250\212\345\260\217\351\203\255/20230612 \346\210\277\345\261\213\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/47 \346\250\212\345\260\217\351\203\255/20230612 \346\210\277\345\261\213\347\256\241\347\220\206\347\263\273\347\273\237.md" new file mode 100644 index 0000000..c49097b --- /dev/null +++ "b/47 \346\250\212\345\260\217\351\203\255/20230612 \346\210\277\345\261\213\347\256\241\347\220\206\347\263\273\347\273\237.md" @@ -0,0 +1,522 @@ +# 房屋管理系统 + +```java +create database test charset utf8; + use test; + # (房屋类型表) + create table house_type + ( + id int primary key auto_increment, # 编号 主键,自动增长列 + type varchar(50) not null # 房屋类型 不允许为空 + + ); + insert into house_type values + (null,'两室一厅'), + (null,'一室一厅'), + (null,'三室一厅'); + # house_info (房源信息表) + create table house_info + ( + id int primary key auto_increment, # 编号 主键,自动增长列 + lease_mode varchar(50), # 租赁方式 可以为空 + rent double not null, # 租金 不允许为空 + contacts varchar(20), # 联系人 可以为空 + deposit_method varchar(20), # 押金方式 可以为空 + house_type_id int, # 房屋类型 外键 + address varchar(200) not null, # 详细地址 不允许为空 + foreign key (house_type_id) references house_type (id) + ); + +// 类 + package bean; + +public class HouseInfo { + + + + + + + + + private int id; // 编号 + private String leaseMode; // 租赁方式 + private double rent; // 租金 + private String contacts; // 联系人 + private String depositMethod; // 押金方式 + private int typeId; // 房屋类型 + private String address; // 详细地址 + private String type; // 房屋类型 + + public HouseInfo(int id, String leaseMode, double rent, String contacts, String depositMethod, int typeId, String address, String type) { + this.id = id; + this.leaseMode = leaseMode; + this.rent = rent; + this.contacts = contacts; + this.depositMethod = depositMethod; + this.typeId = typeId; + this.address = address; + this.type = type; + } + + public HouseInfo() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getLeaseMode() { + return leaseMode; + } + + public void setLeaseMode(String leaseMode) { + this.leaseMode = leaseMode; + } + + public double getRent() { + return rent; + } + + public void setRent(double rent) { + this.rent = rent; + } + + public String getContacts() { + return contacts; + } + + public void setContacts(String contacts) { + this.contacts = contacts; + } + + public String getDepositMethod() { + return depositMethod; + } + + public void setDepositMethod(String depositMethod) { + this.depositMethod = depositMethod; + } + + public int getTypeId() { + return typeId; + } + + public void setTypeId(int typeId) { + this.typeId = typeId; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "HouseInfo{" + + "id=" + id + + ", leaseMode='" + leaseMode + '\'' + + ", rent=" + rent + + ", contacts='" + contacts + '\'' + + ", depositMethod='" + depositMethod + '\'' + + ", typeId=" + typeId + + ", address='" + address + '\'' + + ", type='" + type + '\'' + + '}'; + } +} +package bean; + +public class HouseType { + private int id; + private String type; + + @Override + public String toString() { + return "HouseType{" + + "id=" + id + + ", 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; + } + + public HouseType() { + } + + public HouseType(int id, String type) { + this.id = id; + this.type = type; + } +} +// servlet +package servlet; + + import bean.HouseInfo; + import bean.HouseType; + 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("/add") +public class AddServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // 1 编写sql语句 + String sql = "select * from house_type"; + // 2 调用工具类结果集 + ResultSet rs = DBUtil.query(sql); + // 3 写一个集合,接收数据,遍历集合,到一个对象中去 + ArrayList list = new ArrayList<>(); + try { + while(rs.next()){ + int id = rs.getInt(1); + String type = rs.getString(2); + HouseType houseType = new HouseType(id, type); + list.add(houseType); + } + } catch (SQLException e) { + e.printStackTrace(); + } + // 4 将集合添加到request中 + request.setAttribute("list",list); + // 5 请求转发到jsp + request.getRequestDispatcher("/WEB-INF/add.jsp").forward(request,response); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // 1 处理乱码 + request.setCharacterEncoding("utf-8"); + // 2 接收表单数据 + String leaseMode = request.getParameter("leaseMode"); + String rent = request.getParameter("rent"); + String contacts = request.getParameter("contacts"); + String depositMethod = request.getParameter("depositMethod"); + String type = request.getParameter("type"); + String address = request.getParameter("address"); + // 3 编写sql语句 + String sql = "insert into house_info values(?,?,?,?,?,?,?)"; + // 4 调用工具类,执行sql,得到影响的行数 + int i = DBUtil.update(sql,null,leaseMode,rent,contacts,depositMethod,type,address); + // 5 根据影响的行数,进行判断提示 + if (i>0){ + response.sendRedirect("/list"); + }else{ + request.setAttribute("msg","添加失败"); + request.getRequestDispatcher("/WEB-INF/msg.jsp").forward(request,response); + } + } +} + +package servlet; + + import utils.DBUtil; + + import javax.servlet.*; + import javax.servlet.http.*; + import javax.servlet.annotation.*; + import java.io.IOException; + +@WebServlet("/delete") +public class DeleteServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // 根据id删除对应的房源 + // 1 获取id的值 + String id = request.getParameter("id"); + // 2 编写sql语句 + String sql = "delete from house_info where id=?"; + // 3 调用工具类,执行sql,得到影响的行数 + int i = DBUtil.update(sql, id); + // 4 根据影响的行数,进行判断提示 + if (i>0){ + response.sendRedirect("/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 { + + } +} + + package servlet; + + import bean.HouseInfo; + 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 { + // 1 编写sql语句 + String sql = "select * from house_info i,house_type t where i.house_type_id=t.id"; + // 2 调用工具类结果集 + ResultSet rs = DBUtil.query(sql); + // 3 写一个集合,接收数据,遍历集合,到一个对象中去 + ArrayList list = new ArrayList<>(); + try { + while(rs.next()){ + int id = rs.getInt(1); + String mode = rs.getString(2); + double rent = rs.getDouble(3); + String contacts = rs.getString(4); + String method = rs.getString(5); + int typeId = rs.getInt(6); + String address = rs.getString(7); + String type = rs.getString(9); + HouseInfo houseInfo = new HouseInfo(id, mode, rent, contacts, method, typeId, address, type); + list.add(houseInfo); + } + } catch (SQLException e) { + e.printStackTrace(); + } + // 4 将集合添加到request中 + request.setAttribute("list",list); + // 5 请求转发到jsp + request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} + +package servlet; + + import bean.HouseInfo; + 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("/search") +public class SearchServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // 0 编写字符集,防止乱码 + request.setCharacterEncoding("utf-8"); + // 1 编写sql语句 + String username = request.getParameter("username"); + String sql = "select * from house_info i,house_type t where i.house_type_id=t.id and contacts like ?"; + // 2 调用DBUtil工具类 + ResultSet rs = DBUtil.query(sql, "%" + username + "%"); + // 3 将结果集变成一个集合 + ArrayList list = new ArrayList<>(); + // 3.5 遍历list集合,将元素封装成一个对象,添加到集合里 + try { + while(rs.next()){ + int id = rs.getInt(1); + String mode = rs.getString(2); + double rent = rs.getDouble(3); + String contacts = rs.getString(4); + String method = rs.getString(5); + int typeId = rs.getInt(6); + String address = rs.getString(7); + String type = rs.getString(9); + HouseInfo houseInfo = new HouseInfo(id, mode, rent, contacts, method, typeId, address, type); + list.add(houseInfo); + } + } catch (SQLException e) { + e.printStackTrace(); + } + // 4 将集合添加到request中 + request.setAttribute("list",list); + // 5 请求转发到jsp + request.getRequestDispatcher("/WEB-INF/list.jsp").forward(request,response); + } +} +<%-- jsp --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + +房屋管理系统 + + +
+ +
+
+
+ + + 姓名: + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
编号租赁方式租金(元)联系人押金方式房屋类型详细地址操作
${h.id}${h.leaseMode}${h.rent}${h.contacts}${h.depositMethod}${h.type}${h.address} +删除 +
+ + + + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + +添加数据 + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 租赁方式: + + +
+ 租金(元): + + +
+ 联系人: + + +
+ 押金方式: + + +
+ 房屋类型: + + +
+ 详细地址: + + +
+ +
+
+ + + + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + +Title + + +${msg} + + +``` \ No newline at end of file -- Gitee