📄 saveorderaction.java
字号:
/*
* Created on Mar 8, 2004
*
* (c) 2004, Mark Eagle, meagle@meagle.com
* relased under terms of the GNU public license
* http://www.gnu.org/licenses/licenses.html#TOCGPL
*/
package com.meagle.action;
import java.util.HashSet;
import java.util.Set;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.meagle.bo.Order;
import com.meagle.bo.OrderLineItem;
import com.meagle.forms.OrderForm;
/**
* This will save a new order in the database
*
* @author meagle
*/
public class SaveOrderAction extends BaseAction {
/**
* Default constructor
*/
public SaveOrderAction() {
super();
}
/**
* Implementation for Struts execute
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.lang.Exception {
// Assemble the order from the form
OrderForm oForm = (OrderForm) form;
Order order = new Order();
order.setUserName(oForm.getWhoPlacedOrder());
Set lineItems = new HashSet();
if (oForm.getItemDesc_1() != null && oForm.getItemDesc_1().length() > 0) {
OrderLineItem item = new OrderLineItem();
item.setDescription(oForm.getItemDesc_1());
item.setLineItemPrice(oForm.getItemPrice_1());
lineItems.add(item);
item.setOrder(order);
}
if (oForm.getItemDesc_2() != null && oForm.getItemDesc_2().length() > 0) {
OrderLineItem item = new OrderLineItem();
item.setDescription(oForm.getItemDesc_2());
item.setLineItemPrice(oForm.getItemPrice_2());
lineItems.add(item);
item.setOrder(order);
}
if (oForm.getItemDesc_3() != null && oForm.getItemDesc_3().length() > 0) {
OrderLineItem item = new OrderLineItem();
item.setDescription(oForm.getItemDesc_3());
item.setLineItemPrice(oForm.getItemPrice_3());
lineItems.add(item);
item.setOrder(order);
}
order.setOrderLineItems(lineItems);
// delegate the save to the service layer and further upstream
getOrderService().saveNewOrder(order);
oForm.setOrder(order);
ActionErrors errors = new ActionErrors();
//errors.add(Globals.ERROR_KEY, new ActionError("message.order.saved.successfully"));
errors.add(Globals.ERROR_KEY, new ActionError("保存错误"));
saveErrors(request, errors);
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -