滴滴打车

#数据库record
CREATE TABLE record (
id int(11) NOT NULL AUTO_INCREMENT,
type int(11) NOT NULL,
startAddress varchar(50) NOT NULL,
targetAddress varchar(50) NOT NULL,
startTime datetime NOT NULL,
status int(11) NOT NULL,
PRIMARY KEY (id)
)
#实体类

package com.neu.entity;

import java.util.Date;

public class Record {
	private Integer id;
	private Integer type;
	private String startAddress;
	private String targetAddress;
	private Date startTime;
	private Integer status;
	public Record() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Record(Integer id, Integer type, String startAddress, String targetAddress, Date startTime, Integer status) {
		super();
		this.id = id;
		this.type = type;
		this.startAddress = startAddress;
		this.targetAddress = targetAddress;
		this.startTime = startTime;
		this.status = status;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	public String getStartAddress() {
		return startAddress;
	}
	public void setStartAddress(String startAddress) {
		this.startAddress = startAddress;
	}
	public String getTargetAddress() {
		return targetAddress;
	}
	public void setTargetAddress(String targetAddress) {
		this.targetAddress = targetAddress;
	}
	public Date getStartTime() {
		return startTime;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((startAddress == null) ? 0 : startAddress.hashCode());
		result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result + ((targetAddress == null) ? 0 : targetAddress.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Record other = (Record) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (startAddress == null) {
			if (other.startAddress != null)
				return false;
		} else if (!startAddress.equals(other.startAddress))
			return false;
		if (startTime == null) {
			if (other.startTime != null)
				return false;
		} else if (!startTime.equals(other.startTime))
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		if (targetAddress == null) {
			if (other.targetAddress != null)
				return false;
		} else if (!targetAddress.equals(other.targetAddress))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Record [id=" + id + ", type=" + type + ", startAddress=" + startAddress + ", targetAddress="
				+ targetAddress + ", startTime=" + startTime + ", status=" + status + "]";
	}

}

#RecordDao.java

package com.neu.dao;

import java.util.Date;
import java.util.List;

import com.neu.entity.Record;

public interface RecordDao {
	List<Record> getPage(int pageNum,int pageSize) throws Exception;
	int getCount() throws Exception;
	int getInsert(int type,String startAddress,String targetAddress,Date startTime,int status) throws Exception;
	int getUpdate(int id,int status) throws Exception;

}

#RecordDaoImpl.java

package com.neu.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.neu.entity.Record;

public class RecordDaoImpl implements RecordDao {

	@Override
	public List<Record> getPage(int pageNum, int pageSize) throws Exception {
		Connection connection = JDBCUtil.getConnection();
		String sql = "select * from record limit ?,?";
		ResultSet rs = JDBCUtil.executeQuery(connection, sql, new Object[]{(pageNum-1)*pageSize,pageSize});
		List<Record> list = new ArrayList<>();
		Record record = null;
		int id;
		int type;
		String startAddress;
		String targetAddress;
		Date startTime;
		int status;
		while(rs.next()) {
			id = rs.getInt("id");
			type = rs.getInt("type");
			startAddress = rs.getString("startAddress");
			targetAddress = rs.getString("targetAddress");
			startTime = rs.getTimestamp("startTime");
			status = rs.getInt("status");
			record = new Record(id, type, startAddress, targetAddress, startTime, status);
			list.add(record);
		}
		JDBCUtil.closeConnection(connection);
		return list;
	}

	@Override
	public int getCount() throws Exception {
		Connection connection = JDBCUtil.getConnection();
		String sql = "select count(*) from record";
		ResultSet rs = JDBCUtil.executeQuery(connection, sql, null);
		int count = 0;
		if(rs.next()) {
			count = rs.getInt(1);
		}
		return count;
	}

	@Override
	public int getInsert(int type,String startAddress,String targetAddress,Date startTime,int status) throws Exception {
		String sql = "insert into record(type,startAddress,targetAddress,startTime,status) values (?,?,?,?,?)";
		int n = JDBCUtil.executeUpdate(sql, new Object[] {type,startAddress,targetAddress,startTime,status});
		return n;
	}

	@Override
	public int getUpdate(int id,int status) throws Exception {
		String sql = "update record set status = ? where id = ?";
		int n = JDBCUtil.executeUpdate(sql, new Object[] {status,id});
		return n;
	}

}

#RecordService.java

package com.neu.sevice;

import java.util.Date;
import java.util.List;

import com.neu.entity.Record;

public interface RecordService {
	List<Record> getPage(int pageNum,int pageSize) throws Exception;
	int getCount() throws Exception;
	int getInsert(int type,String startAddress,String targetAddress,Date startTime,int status) throws Exception;
	int getUpdate(int id,int status) throws Exception;
}

#RecordServiceImpl.java

package com.neu.sevice;

import java.util.Date;
import java.util.List;

import com.neu.dao.RecordDao;
import com.neu.dao.RecordDaoImpl;
import com.neu.entity.Record;

public class RecordServiceImpl implements RecordService {
	private RecordDao recordDao = new RecordDaoImpl();
	@Override
	public List<Record> getPage(int pageNum, int pageSize) throws Exception {
		// TODO Auto-generated method stub
		return recordDao.getPage(pageNum, pageSize);
	}

	@Override
	public int getCount() throws Exception {
		// TODO Auto-generated method stub
		return recordDao.getCount();
	}

	

	@Override
	public int getUpdate(int id, int status) throws Exception {
		// TODO Auto-generated method stub
		return recordDao.getUpdate(id, status);
	}

	@Override
	public int getInsert(int type, String startAddress, String targetAddress, Date startTime, int status)
			throws Exception {
		// TODO Auto-generated method stub
		return recordDao.getInsert(type, startAddress, targetAddress, startTime, status);
	}

	

}

#pageRecordServlet.java

package com.neu.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class pageRecordServlet
 */
@WebServlet("/pageRecord")
public class pageRecordServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int type = Integer.parseInt(request.getParameter("lei"));
		if(type==1) {
			request.setAttribute("type", type);
			request.getRequestDispatcher("WEB-INF/record/kuaiche.jsp").forward(request, response);
		}else if(type==2) {
			request.setAttribute("type", type);
			request.getRequestDispatcher("WEB-INF/record/shunfengche.jsp").forward(request, response);
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

#InsertRecordServlet.java

package com.neu.servlet;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

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 com.neu.entity.Record;
import com.neu.sevice.RecordService;
import com.neu.sevice.RecordServiceImpl;

/**
 * Servlet implementation class InsertRecordServlet
 */
@WebServlet("/InsertRecord")
public class InsertRecordServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		int type = Integer.parseInt(request.getParameter("type"));
		String startAddress = request.getParameter("startAddress");
		String targetAddress = request.getParameter("targetAddress");
		String startTime = request.getParameter("startTime");
		Date parse = null;
		try {
			if(startTime==null) {
				parse = new Date();
			}else {
				parse = d.parse(startTime);
			}
			
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		int status = 1;
		
		RecordService recordService = new RecordServiceImpl();
		try {
			recordService.getInsert(type, startAddress, targetAddress, parse, status);
			response.sendRedirect(request.getContextPath()+"/showRecord");
//			request.getRequestDispatcher("WEB-INF/record/show.jsp").forward(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

#showRecordServle.java

package com.neu.servlet;

import java.io.IOException;
import java.util.List;

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 com.neu.entity.Record;
import com.neu.sevice.RecordService;
import com.neu.sevice.RecordServiceImpl;

/**
 * Servlet implementation class showRecordServlet
 */
@WebServlet("/showRecord")
public class showRecordServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int pageNum = 1;
		int pageSize = 3;
		if(request.getParameter("pageNum")!=null) {
			pageNum = Integer.parseInt(request.getParameter("pageNum"));
		}
		RecordService recordService = new RecordServiceImpl();
		try {
			List<Record> list = recordService.getPage(pageNum, pageSize);
			request.setAttribute("list", list);
			int count = recordService.getCount();
			int num = count%pageSize==0?count/pageSize:count/pageSize+1;
			request.setAttribute("num", num);
			request.setAttribute("errNum", pageNum);
			request.getRequestDispatcher("WEB-INF/record/show.jsp").forward(request, response);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

#updateRecordServlet.java

package com.neu.servlet;

import java.io.IOException;
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 com.neu.sevice.RecordService;
import com.neu.sevice.RecordServiceImpl;

/**
 * Servlet implementation class updateRecordServlet
 */
@WebServlet("/updateRecord")
public class updateRecordServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int id = Integer.parseInt(request.getParameter("id"));
		int status = Integer.parseInt(request.getParameter("status1"));
		
		RecordService recordService = new RecordServiceImpl();
		
		try {
			recordService.getUpdate(id, status);
			request.getRequestDispatcher("/showRecord").forward(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

#didi.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="${ pageContext.request.contextPath }/pageRecord" method="post">
		<h1>滴滴打车</h1>
		<p>请选择叫车类型:</p>
		<p>
		<input type="radio" name="lei" value="1">快车
		<input type="radio" name="lei" value="2">顺风车
		</p>
		<input type="submit" value="    提  交     ">
	</form>
</body>
</html>

#kuaiche.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function bian(the) {
		var a = document.forms[0].startTime;
		a.disabled=false;
		a.style.backgroundColor="white";
	}
</script>
</head>
<body>
	<h1>${ type==1?"快车":"顺风车" }</h1>
	<form action="${ pageContext.request.contextPath }/InsertRecord?type=${ type }" method="post">
		<table>
			<tr>
				<td>出发地:</td>
				<td><input type="text" name="startAddress"></td>
			</tr>
			<tr>	
				<td>目的地:</td>
				<td><input type="text" name="targetAddress"></td>
			</tr>
			<tr>	
				<td colspan="2"><input type="checkbox"  name="yuyue" onclick="bian(this)">预约时间</td>
			</tr>
				<tr>	
				<td>&nbsp;间:</td>
				<td><input type="text" name="startTime" disabled="true" style="background-color: gainsboro;"}></td>
			</tr>
			<tr>	
				<td colspan="2"><input type="submit" value="  叫 车  "></td>
			</tr>
		</table>
	</form>
</body>
</html>

#shunfengche.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	function bian(the) {
		var a = document.forms[0].startTime;
		a.disabled=false;
		a.style.backgroundColor="white";
	}
</script>
</head>
<body>
	<h1>${ type==1?"快车":"顺风车" }</h1>
	<form action="${ pageContext.request.contextPath }/InsertRecord?type=${ type }" method="post">
		<table>
			<tr>
				<td>出发地:</td>
				<td><input type="text" name="startAddress"></td>
			</tr>
			<tr>	
				<td>目的地:</td>
				<td><input type="text" name="targetAddress"></td>
			</tr>
			<tr>	
				<td colspan="2"><input type="checkbox"  name="yuyue"  onclick="bian(this)">预约时间</td>
			</tr>
				<tr>	
				<td>&nbsp;间:</td>
				<td><input type="text" name="startTime" disabled="true" style="background-color: gainsboro;"}></td>
			</tr>
			<tr>	
				<td colspan="2"><input type="submit" value="  叫 车  "></td>
			</tr>
		</table>
	</form>
</body>
</html>

#show.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<div style="margin-left: 350px">打车记录</div>
	<table border="1" width="700">
		<tr>
			<th>序号</th>
			<th>类型</th>
			<th>出发地</th>
			<th>目的地</th>
			<th>时间</th>
			<th>订单状态</th>
		</tr>
		<c:forEach items="${ list }" var="record">
			<tr>
				<td>${ record.id }</td>
				<td>${ record.type==1?"快车":"顺风车" }</td>
				<td>${ record.startAddress }</td>
				<td>${ record.targetAddress }</td>
				<td><fmt:formatDate value="${ record.startTime }" pattern="yyyy-MM-dd HH:mm"/></td>
				<td>
				<c:if test="${ record.status==1 }">
					<a href="${ pageContext.request.contextPath }/updateRecord?status1=3&&id=${ record.id }">取消订单</a>
					<a href="${ pageContext.request.contextPath }/updateRecord?status1=2&&id=${ record.id }">确认到达</a>
				</c:if>
				<c:if test="${ record.status==3 }">
					已取消
				</c:if>
				<c:if test="${ record.status==2 }">
					已完成
				</c:if>
				</td>
			</tr>
		</c:forEach>
		<tr align="center">
			<td colspan="6">
				<c:if test="${ errNum==1 }">
				<a>上一页</a>
				</c:if>
				<c:if test="${ errNum>1 }">
				<a  href="${ pageContext.request.contextPath }/showRecord?pageNum=${ errNum-1 }">上一页</a>
				</c:if>
				<c:forEach begin="1" end="${ num }" var="pageNum">
					<a href="${ pageContext.request.contextPath }/showRecord?pageNum=${ pageNum }">[${ pageNum }]</a>
				</c:forEach>
				<c:if test="${ errNum==num }">
				<a>下一页</a>
				</c:if>
				<c:if test="${ errNum<num }">
				<a  href="${ pageContext.request.contextPath }/showRecord?pageNum=${ errNum+1 }">下一页</a>
				</c:if>
			</td>
		</tr>
	</table>
	<a href="${ pageContext.request.contextPath }/showRecord?pageNum=1">返回首页</a>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值