 |
返回文章
清单 1. DeleteOrderAction.java
// Package and Import statements omitted
01 public class DeleteOrderAction extends Action {
02
03 public ActionForward execute(ActionMapping mapping, ActionForm form,
04 HttpServletRequest req, HttpServletResponse res) throws Exception {
05
06 String value = req.getParameter("id"); // Get the order id from the request
07 Long id = new Long(value);
08
09 deleteOrder(id);
10
11 return mapping.findForward("success"); // Forward to ListOrdersAction
12 }
13
14 private void deleteOrder(Long id) {
15 Session session = HibernateUtil.currentSession(); // Get a session object
16 Transaction tx = null;
17
18 try {
19 tx = session.beginTransaction(); // Begin the transaction
20 session.delete(new Order(id)); // Delete the Order object
21 tx.commit(); // Commit the transaction
22 } finally {
23 HibernateUtil.closeSession(); // Close the session
24 }
25 }
26 }
|
返回文章
|  |
|