diff --git "a/13 \345\274\240\345\276\267\345\272\267/20230607 \344\275\234\344\270\232.md" "b/13 \345\274\240\345\276\267\345\272\267/20230607 \344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..97a09f122ab9ff19a4c322a2e5be26f0510a6da6 --- /dev/null +++ "b/13 \345\274\240\345\276\267\345\272\267/20230607 \344\275\234\344\270\232.md" @@ -0,0 +1,259 @@ +``` +package bean; + +public class Hinfo { + private int id; //编号 + private String lease;//租赁 + private double rent;//祖金 + private String contacts;//联系人 + private String deposit;//押金 + private int houseid;//房屋 + private String address;//地址 + + public Hinfo(int id, String lease, double rent, String contacts, String deposit, int houseid, String address) { + this.id = id; + this.lease = lease; + this.rent = rent; + this.contacts = contacts; + this.deposit = deposit; + this.houseid = houseid; + this.address = address; + } + + public Hinfo() { + } + + + @Override + public String toString() { + return "Hinfo{" + + "id=" + id + + ", lease='" + lease + '\'' + + ", rent=" + rent + + ", contacts='" + contacts + '\'' + + ", deposit='" + deposit + '\'' + + ", houseid=" + houseid + + ", address='" + address + '\'' + + '}'; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getLease() { + return lease; + } + + public void setLease(String lease) { + this.lease = lease; + } + + 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 getDeposit() { + return deposit; + } + + public void setDeposit(String deposit) { + this.deposit = deposit; + } + + public int getHouseid() { + return houseid; + } + + public void setHouseid(int houseid) { + this.houseid = houseid; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } +} +package bean; + +public class Htype { + private int id; + private String type; + + public Htype(int id, String type) { + this.id = id; + this.type = type; + } + + public Htype() { + } + + 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 "Htype{" + + "id=" + id + + ", type='" + type + '\'' + + '}'; + } +} +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 list extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String sql="select * from house_info i,house_type t where i.id=t.id"; + ResultSet rs = DBUtil.query(sql); + ArrayList list = new ArrayList<>(); + while (rs.next()){ + + int id =rs.getInt(1); + String mode =rs.getNString(2); + int rent =rs.getInt(3); + String contacts =rs.getNString(4); + String deposit =rs.getNString(5); + int house =rs.getInt(6); + int add =rs.getInt(7); + int tid =rs.getInt(8); + String type =rs.getNString(9); + Object info = new Object(id, mode, rent, contacts, deposit, house, add, tid, type); + list.add(info); + } + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} +package utils; + +import java.sql.*; + +public class DBUtil { +// 1.定义主机 用户名 密码 + static String url="jdbc:mysql///test?characterEncoding=utf8"; + static String user="root"; + static String pwd="root"; +// 2.获取连接对象 + static { + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } +} +// 3.获取连接对象 + public static Connection getConn() throws SQLException { + Connection conn = DriverManager.getConnection(url, user, pwd); + return conn; + } +// 4.通用查询 + public static ResultSet query(String sql, Object...keys) { + //拿连接 + ResultSet rs; + try { + Connection conn = getConn(); + //执行sql + PreparedStatement pst = conn.prepareStatement(sql); + //遍历keys + 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; + } + +} +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-07 + Time: 11:08 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + + + + + + + + + + + + + + + + + + + + + + + +
编号租赁方式租金联系人押金方式房屋类型详细地址
${h.id}${h.lease}${h.rent}${h.contacts}${h.deposit}${h.houseid}${h.address}
+ + + + +``` +