Java Online Book Mall (7) Order module 2_java

Source: Internet
Author: User
Tags foreach uuid

The example of this article for everyone to share the Java Online Book Mall order module specific code, for your reference, the specific content as follows

1. My Order---Check

Search ORDER BY user
Page-pagebean<order> Query

<div class= "Divmain" > <div class= "divtitle" > <span style= "margin-left:150px;margin-right:280px"; > Commodity Information </span> <span style= "MARGIN-LEFT:40PX;MARGIN-RIGHT:38PX;" > Amount </span> <span style= "margin-left:50px;margin-right:40px;" > Order Status </span> <span style= "margin-left:50px;margin-right:50px;"
 > Operations </span> </div> <table align= "center" border= "0" width= "100%" cellpadding= "0" cellspacing= "0" > <c:foreach items= "${pb.beanlist}" var= "Order" > <tr class= "tt" > <td width= "320px" > PO Number: <a href= "&L T;c:url value= '/orderservlet?method=load&oid=${order.oid} '/> ' >${order.oid}</a></td> Width= "200px" > Next single time: ${order.ordertime}</td> <td> </td> <td> </td> <td> </t d> <td> </td> </tr> <tr style= "padding-top:10px; padding-bottom:10px; " > <td colspan= "2" > <c:foreach items= "${order.orderitemlist } "var=" OrderItem > <a class= "link2" href= "<c:url value= '/bookservlet?method=load&bid=${" OrderItem.book.bid} '/> ' >  "/> </a> </c:forEach> </td> <td width=" 115px "> <span class=" price_t ">¥${order. Total}</span> </td> <td width= "142px" > <c:choose> <c:when test= "${order.status eq 1} "> (Waiting for payment) </c:when> <c:when test=" ${order.status eq 2} "> (Ready to Ship) </c:when> <c:when test=" ${order  Status eq 3} "> (Waiting for confirmation) </c:when> <c:when test=" ${order.status eq 4} "> (transaction successful) </c:when> <c:when test= "${order.status eq 5}" > (canceled) </c:when> </c:choose> </td> <td> <a href= "<c : URL value= '/orderservlet?method=load&oid=${order.oid} '/> ' > View </a><br/> <c:if test= ' ${ Order.status eq 1} "> <a href=" <c:url VALue= '/orderservlet?method=paymentpre&oid=${order.oid} '/> ' > Pay </a><br/> <a href= ' <c: URL value= '/orderservlet?method=load&oid=${order.oid}&btn=cancel '/> ' > Cancel </a><br/> </ c:if> <c:if test= "${order.status eq 3}" > <a href= "<c:url value="/orderservlet?method=load&oid=${o Rder.oid}&btn=confirm '/> ' > confirmed receipt </a><br/> </c:if> </td> </tr> </c:foreach > </table> </div>
 

2. Order Module Generation Order

Orderservlet

Public String Createorder (httpservletrequest req, HttpServletResponse resp) throws Servletexception, IOException {/* * 1.
 Gets the ID of all cart entries, the query */String Cartitemids = Req.getparameter ("Cartitemids");
 list<cartitem> cartitemlist = Cartitemservice.loadcartitems (cartitemids);
 if (cartitemlist.size () = = 0) {req.setattribute ("code", "error"); Req.setattribute ("msg", "You do not have the choice to buy the book, cannot order!"
 ");
 return "f:/jsps/msg.jsp"; } * * 2.
 Create order */order = New Order ();
 Order.setoid (Commonutils.uuid ());//Set Primary key Order.setordertime (String.Format ("%tf%<tt", New Date ()); Order.setstatus (1)//set state, 1 for unpaid order.setaddress (req.getparameter ("Address"))//Set up receipt addresses user Owner = (user)
 Req.getsession (). getattribute ("Sessionuser");
 Order.setowner (owner),/Set the order owner BigDecimal total = new BigDecimal ("0");
 for (Cartitem cartitem:cartitemlist) {total = Total.add (new BigDecimal (Cartitem.getsubtotal () + "")); } order.settotal (Total.doublevalue ());//Set Total/* 3. Create List<orderitem> * A cartitem corresponds to a orderitem * * list<orderitem> orderitemlist = new arraylist<orderitem> ();
 for (Cartitem cartitem:cartitemlist) {OrderItem OrderItem = new OrderItem ();
 Orderitem.setorderitemid (Commonutils.uuid ());//Set Primary key orderitem.setquantity (Cartitem.getquantity ());
 Orderitem.setsubtotal (Cartitem.getsubtotal ());
 Orderitem.setbook (Cartitem.getbook ());
 Orderitem.setorder (order);
 Orderitemlist.add (OrderItem);
 
 } order.setorderitemlist (Orderitemlist); * * 4.
 
 Call service Complete Add/orderservice.createorder (order);
 Delete Shopping Cart entry cartitemservice.batchdelete (cartitemids); * * 5.
 Save the order and forward it to ordersucc.jsp/Req.setattribute ("Orders");
return "f:/jsps/order/ordersucc.jsp";
 }

Orderdao

public void Add throws SQLException {/
 * 1. Insert order/
 String sql = INSERT INTO T_order value S (?,?,?,?,?,?) ";
 Object[] params = {order.getoid (), Order.getordertime (), Order.gettotal (), Order.getstatus (), order.getaddress (
  ) ,
  Order.getowner (). Getuid ()};
 Qr.update (sql, params);
 * * 2. Loop through all the items of the order, let each entry generate a object[]
 * Multiple entries on the corresponding object[][]
 * Execute batch, complete insert Order entry * *
 sql = "Insert into T_orderitem values (?,?,?,?,?,?,?,?) ";
 int len = Order.getorderitemlist (). Size ();
 object[][] Objs = new object[len][];
 for (int i = 0; i < len; i++) {
 OrderItem item = order.getorderitemlist (). get (i);
 Objs[i] = new Object[]{item.getorderitemid (), item.getquantity (),
  item.getsubtotal (), Item.getbook (). GetBid (), Item.getbook (). Getbname (), Item.getbook (), Getcurrprice (), Item.getbook ()
  . Getimage_b (), order.getoid () };
 }
 Qr.batch (SQL, OBJS);

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.