?? addproductaction.java
字號:
package com.briup.admin.web.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.briup.admin.service.IAdminService;import com.briup.admin.web.form.AddProductForm;import com.briup.common.dao.pojo.Product;import com.briup.common.dao.pojo.ProductType;/* * 該action為添加品牌和修改品牌的共用模塊 * *//** * class AddProduct * * @author lyz */public class AddProductAction extends Action { IAdminService adminService; public void setAdminService(IAdminService adminService) { this.adminService = adminService; } public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 通過form從相應的jsp(addProduct.jsp和modifyProduct.jsp)中獲得需要的字段信息 AddProductForm addproForm = (AddProductForm) form; String productName = addproForm.getProductName(); String productTypeId = addproForm.getProductType(); Double baseFee = addproForm.getBaseFee(); Double rateFee = addproForm.getRateFee(); Long dailyLimit = addproForm.getDailyLimit(); Long monthLimit = addproForm.getMonthLimit(); Long upLimit = addproForm.getUpLimit(); Long downLimit = addproForm.getDownLimit(); Double sfee = addproForm.getSfee(); String remark = addproForm.getRemark(); try { // 根據(jù)取得的品牌名去數(shù)據(jù)庫中查找是否已經(jīng)存在該信息 Product pro = adminService.findProduct(productName); // 若存在,從表中刪除掉該記錄,在根據(jù)修改信息重新保存 if (pro != null) { request.setAttribute("message", "該品牌已經(jīng)存在!"); } // 根據(jù)所得信息進行向數(shù)據(jù)庫中保存 Product product = new Product(); ProductType proType = adminService.findProductById(Long .parseLong(productTypeId)); product.setName(productName); product.setBaseFee(baseFee); product.setRateFee(rateFee); product.setDailyLimit(dailyLimit); product.setMonthLimit(monthLimit); product.setUpLimit(upLimit); product.setDownLimit(downLimit); product.setSfee(sfee); product.setRemark(remark); product.setProductType(proType); adminService.save(product); // 成功后,跳轉(zhuǎn)到所有的品牌列表 return mapping.findForward("success"); } catch (Exception e) { e.printStackTrace(); // 不成功顯示品牌添加失敗,并停留在該品牌添加界面(addProduct.jsp/modifyProduct.jsp) request.setAttribute("message", "品牌增加失敗"); return mapping.findForward("failed"); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -