📄 customertypefindbyprimarykeyaction.java
字号:
package com.relationinfo.customertrace.struts.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMessage;
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.relationinfo.customertrace.dao.CustomerTypeDao;
import com.relationinfo.customertrace.dto.CustomerType;
import com.relationinfo.customertrace.factory.CustomerTypeDaoFactory;
import com.relationinfo.customertrace.struts.forms.CustomerTypeForm;
public class CustomerTypeFindByPrimaryKeyAction extends Action
{
/**
* Method 'execute'
*
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
try {
// 解析参数
java.lang.String _customertypecode = request.getParameter("customertypecode");
//创建Dao类
CustomerTypeDao dao = CustomerTypeDaoFactory.create();
// 执行查询
CustomerType dto = dao.findByPrimaryKey(_customertypecode);
// 检测是否查到记录
if (dto == null) {
throw new RuntimeException( "Finder did not return any data" );
}
String crudMethod = request.getParameter("crudMethod");
if (crudMethod == null) {
crudMethod = "view";
}
// populate a struts form
CustomerTypeForm customerTypeForm = new CustomerTypeForm();
customerTypeForm.setCrudMethod( request.getParameter("crudMethod") );
customerTypeForm.setCustomertypecode(dto.getCustomertypecode());
customerTypeForm.setCustomertypename(dto.getCustomertypename());
// 存储结果
request.getSession().setAttribute( "CustomerType", customerTypeForm );
return mapping.findForward( crudMethod );
}
catch (Exception e) {
ActionErrors _errors = new ActionErrors();
_errors.add( ActionErrors.GLOBAL_MESSAGE, new ActionMessage("internal.error", e.getClass().getName() + ": " + e.getMessage() ) );
saveErrors( request, _errors );
return mapping.findForward( "failure" );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -