?? customerfindbyprimarykeyaction.java
字號:
package com.relationinfo.customertrace.struts.actions;
import org.apache.struts.*;
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.*;
import java.math.*;
import com.relationinfo.customertrace.dao.*;
import com.relationinfo.customertrace.dto.*;
import com.relationinfo.customertrace.factory.*;
import com.relationinfo.customertrace.struts.forms.*;
public class CustomerFindByPrimaryKeyAction 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 _customercode = request.getParameter("customercode");
//創建Dao類
CustomerDao dao = CustomerDaoFactory.create();
// 執行查詢
Customer dto = dao.findByPrimaryKey(_customercode);
// 檢測是否查到記錄
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
CustomerForm customerForm = new CustomerForm();
customerForm.setCrudMethod( request.getParameter("crudMethod") );
customerForm.setCustomercode(dto.getCustomercode());
customerForm.setCustomertypecode(dto.getCustomertypecode());
customerForm.setCustomername(dto.getCustomername());
customerForm.setAddress(dto.getAddress());
customerForm.setPhone(dto.getPhone());
customerForm.setMobile(dto.getMobile());
customerForm.setEmail(dto.getEmail());
customerForm.setBirthday(dto.getBirthday() == null ? null : DateFormat.getDateInstance().format( dto.getBirthday()));
customerForm.setHobby(dto.getHobby());
customerForm.setNote(dto.getNote());
// 存儲結果
request.getSession().setAttribute( "Customer", customerForm );
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 + -