getitemdetailaction.java

来自「网上商店 新增功能: 1」· Java 代码 · 共 44 行

JAVA
44
字号
package netstore.catalog;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import netstore.framework.exceptions.BaseException;
import netstore.framework.NetstoreBaseAction;
import netstore.businessobjects.Item;
import netstore.framework.util.IConstants;
import netstore.service.*;
import org.apache.log4j.*;

/**
 * An action that gets an Item based on an id parameter in the request and
 * then inserts the item into an ActionForm and forwards to whatever
 * path is defined as Success for this action mapping.
 * 通过id找到具体的产品
 */
public class GetItemDetailAction extends NetstoreBaseAction {
	private static Logger logger = Logger.getLogger(GetItemDetailAction.class.getName());
  public ActionForward execute( ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response )
   throws Exception {
	  
    // Get the primary key of the item from the request
    Long itemId =new Long( request.getParameter( IConstants.ID_KEY ));
    logger.info("Now itemid:"+itemId);
    // Call the netstore service and ask it for an Item
    ProdServiceImpl serviceImpl = getProdService();

    Item item = serviceImpl.getItemById( itemId );

    // Set the returned Item into the Dynamic Action Form
    // The parameter name 'view' is what is defined in the struts-config
    //传参数,实际上一个产品对象
    ((DynaActionForm)form).set("view", item);


    // Return the ActionForward that is defined for the success condition
    return mapping.findForward( IConstants.SUCCESS_KEY );
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?