📄 addproduct.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; /* * 这是AddProductAction的原版本(功能类似) * 名字定义不规范(工程内没有使用) * *//** *class AddProduct *@author briup *Date 2008-2-23 下午04:07:57 */public class AddProduct 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获取所有的提交字段 AddProductForm addproForm = (AddProductForm)form; String productName = addproForm.getProductName(); String productTypeName = 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(); //创建Product对象和ProductType对象 Product product = new Product(); ProductType proType = new ProductType(); //设置Product对象的属性 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); //设置ProductType对象的属性 proType.setName(productTypeName); proType.setRemark(productTypeName); //将两个对象(Product和ProductType)相关联 product.setProductType(proType); try{ //级联保存到数据库 adminService.save(product); return mapping.findForward("success") ; }catch(Exception e){ e.printStackTrace(); request.setAttribute("message", "品牌增加失败"); return mapping.findForward("failed") ; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -