📄 purchase.java
字号:
package business;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import dao.PurchaseDao;
import orm.Flight;
import orm.OrderItem;
public class Purchase {
private PurchaseDao purchasedao;
public PurchaseDao getPurchasedao(){
return purchasedao;
}
public void setPurchasedao(PurchaseDao purchasedao)
{
this.purchasedao=purchasedao;
}
public void list(HttpServletRequest request,JspWriter out)
throws Exception{
String tmp=(String)request.getParameter("p_page");
if(tmp!=null)
{
listpage(request,out,Integer.parseInt(tmp));
}
else
{
listpage(request,out,1);
}
}
public void listpage(HttpServletRequest request,JspWriter out,int page)
throws Exception{
List list=purchasedao.getAllFlights();
if(list==null)
{
out.print("没有可售的机票");
return;
}
int total=list.size();
int count=0;
Iterator it=list.iterator();
OrderItem item=null;
Flight flight;
int totalpage=0;
totalpage=total/5;
if(total>totalpage*5)
{
totalpage++;
}
while(count<(page-1)*5&&it.hasNext())
{
it.next();
count++;
}
count=0;
out.print(" <table width=90% border=5 cellspacing=0 cellpadding=0>"+
"<tr bgcolor=#0099FF>"+
"<td width=10%>航班号</td>"+
"<td width=10% >出发地点</td>"+
"<td width=10% >到达地点</td>"+
"<td width=15%>出发日期</td>"+
"<td width=15%>出发时间</td>"+
"<td width=10%>价格</td>"+
"<td width=10%>可售机票</td>"+
"<td width=20%>预定</td>"+
"</tr>"
);
while(it.hasNext()&&count<5){
item=(OrderItem)it.next();
flight=(Flight)item.getFlight();
out.print("<tr>"+
"<td>"+flight.getFlight_no()+"</td>"+
"<td>"+flight.getStart_place()+"</td>"+
"<td>"+flight.getEnd_place()+"</td>"+
"<td>"+item.getDate()+"</td>"+
"<td>"+flight.getstarttime()+"</td>"+
"<td>"+flight.getPrice()+"</td>");
if(item.getFcount()<=0)
{
out.print( "<td>缺票</td>");
out.print("<td>缺票 </td>");
out.print("</tr>");
}
else
{
out.print( "<td>"+item.getFcount()+"</td>");
out.print("<td><a href=/tikects/Purchase.do?orderitem_id="+item.getId()+">放到购物车</a></td>");
out.print("</tr>");
}
count++;
}
out.print("<tr><td colspan=6 align=center>");
out.print("<table width=50% border=0 cellspacing=0><tr>");
if((page-1) > 0)
out.print("<td width=50%><a href=/tikects/view/purchase.jsp?p_page="+(page-1)+">上一页</a></td>");
else
out.print("<td width=50%>上一页</td>");
if((page-1) < (totalpage-1))
out.print("<td width=50%><a href=/tikects/view/purchase.jsp?p_page="+(page+1)+">下一页</a></td>");
else
out.print("<td width=50%>下一页</td>");
out.print("</tr></table></td></tr>");
out.print("</table>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -