?? orderhelper.java
字號:
package util;import model.*;import java.io.*;import java.util.*;import java.sql.Timestamp;import java.text.*;import org.apache.commons.lang.StringEscapeUtils;public class OrderHelper { public static String printOrder(Order o) { try { Integer id = o.getId(); String user = o.getUser(); List<OrderItem> items = o.getItems(); Timestamp created = o.getCreated(); String created_fmt = (created == null) ? "--" : DateFormat.getDateTimeInstance().format(created); String output = "<table border=\"1\" cellpadding=\"5px\">" + "<tr>" + "<td colspan=\"3\">" + "order id: " + (id != null ? id : "--") + ", user: " + user + "<br />" + "created: " + created_fmt + "</td>" + "</tr>" + "<tr><td>product</td> <td>quantity</td> <td>unit price</td></tr>" ; float total = 0; for (OrderItem item: items) { float flt_price = item.getPrice().floatValue(); String fmt_price = NumberFormat.getCurrencyInstance().format(flt_price); String descrip = ProductsBean.find(item.getProdId()).getDescription(); output += "<tr>" + "<td>" + StringEscapeUtils.escapeHtml(descrip) + "</td>" + "<td>" + item.getQty() + "</td>" + "<td>" + fmt_price + "</td>" + "</tr>" ; total += item.getQty() * flt_price; } String total_fmt = NumberFormat.getCurrencyInstance().format(total); output += "<tr>" + "<td colspan=\"3\">" + "total: " + total_fmt + "</td>" + "</tr>" +"</table>" ; return output; } catch(Exception x) { x.printStackTrace(); System.out.println("error:" + x.getMessage()); return "ERROR"; } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -