java_Web 实战07
java_Web 实战05
这样顾客就只有一个功能没有实现是对于房产信息的操作这里将所有的操作内容加到查询上,在查询之后对于数据进行处理
对于查询,这里用了笨的办法,查到所有数据之后,清洗数据得到需要的数据.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<html>
<head>
<title>Title</title>
<style>
table {
border-collapse: collapse;
border: 1px solid black;
}
th,
td {
border: 1px solid black;
padding: 8px;
}
</style>
</head>
<body>
<form action="/Homes/SelectHouse" method="post">
<P>户型
四室两厅 <input type="radio" name="homeType" value="0">
四室一厅 <input type="radio" name="homeType" value="1">
三室两厅 <input type="radio" name="homeType" value="2">
三室一厅 <input type="radio" name="homeType" value="3">
两室两厅 <input type="radio" name="homeType" value="4">
两室一厅 <input type="radio" name="homeType" value="5">
</P>
<p>地址 <input type="text" name="address"></p>
<P>建造年份 <input type="text" name="year"></P>
<P>建造面积 <input type="text" name="area"></P>
<P>销售报价 <input type="text" name="sales"></P>
<P>销售状态
在售 <input type="radio" name="status" value="0" >
待售 <input type="radio" name="status" value="1">
意向 <input type="radio" name="status" value="2">
售出 <input type="radio" name="status" value="3">
停售 <input type="radio" name="status" value="4">
</P>
<P><input type="submit" value="Submit"></input></P>
</form>
<br>
<table>
<c:forEach items="${list}" var="item" varStatus="status">
<c:if test="${status.count==1}">
<tr>
<th>房产编号</th>
<th>户型</th>
<th>房产地址</th>
<th>建造年份</th>
<th>建造面积</th>
<th>销售报价</th>
<th>销售状态</th>
<th>操作</th>
</tr>
</c:if>
<tr>
<td>${item.houseId}</td>
<td>
<c:if test="${item.homeType.equals(\"0\")}">
四室两厅
</c:if>
<c:if test="${item.homeType.equals(\"1\")}">
四室一厅
</c:if>
<c:if test="${item.homeType.equals(\"2\")}">
三室两厅
</c:if>
<c:if test="${item.homeType.equals(\"3\")}">
三室一厅
</c:if>
<c:if test="${item.homeType.equals(\"4\")}">
两室两厅
</c:if>
<c:if test="${item.homeType.equals(\"5\")}">
两室一厅
</c:if>
</td>
<td>${item.address}</td>
<td>${item.year}</td>
<td>${item.area }</td>
<td>${item.sales}</td>
<td>
<c:if test="${item.status.equals(\"0\")}">在售</c:if>
<c:if test="${item.status.equals(\"1\")}">待售</c:if>
<c:if test="${item.status.equals(\"2\")}">意向</c:if>
<c:if test="${item.status.equals(\"3\")}">售出</c:if>
<c:if test="${item.status.equals(\"4\")}">停售</c:if>
</td>
<td><a href="/Homes/SelectHouseByHouseId?houseId=${item.houseId}">详细</a></td>
</tr>
</c:forEach>
</table>
</body>
</html>
这里将查询和所有的查询的结果在一个界面展示在这个界面输入查询信息,在后端中查询后的到查询结果
package com.home.servlet;
import com.home.pojo.House;
import com.home.pojo.User;
import com.home.service.HouseService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@WebServlet("/SelectHouse")
public class SelectHouseServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String homeType=req.getParameter("homeType");
String address=req.getParameter("address");
String year=req.getParameter("year");
String area =req.getParameter("area");
String sales=req.getParameter("sales");
String type=req.getSession().getAttribute("type").toString();
User user=(User) req.getSession().getAttribute("user");
HouseService houseService=new HouseService();
List<House>list=houseService.selectHouse();
if(homeType!=null&&homeType.equals(""))homeType=null;
if(address!=null&&address.equals(""))address=null;
if(year!=null&&year.equals(""))year=null;
if(area!=null&&area.equals(""))area=null;
if(sales!=null&&sales.equals(""))sales=null;
List<House>list1=new ArrayList<>();
for(House house:list){
if(type.equals("0")&&!house.getStatus().equals("0")){
continue;
}
else if(type.equals("1")&&!house.getAgentId().equals(user.getUsername())){
continue;
}
if(homeType!=null&&!homeType.equals(house.getHomeType())){
continue;
}
if(year!=null&&!year.equals(house.getYear())){
continue;
}
if(address!=null&&house.getAddress().indexOf(address)==-1){
continue;
}
if(area!=null){
double areaDouble=Double.parseDouble(area);
double a=Double.parseDouble(house.getArea());
if(areaDouble>a)continue;
}
if(sales!=null){
double salesDouble=Double.parseDouble(sales);
double s=Double.parseDouble(house.getSales());
if(salesDouble>s)continue;
}
list1.add(house);
}
req.setAttribute("list",list1);
req.getRequestDispatcher("selectHouse.jsp").forward(req, resp);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
}