📄 petaction.java
字号:
// ----------------------------------------------------------
// $Id: $
// Copyright (c) SHSAFE 2005-2006. All Rights Reserved.
// ----------------------------------------------------------
package example.pet;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import com.shsafe.common.database.DatabaseConnection;
import com.shsafe.common.database.DatabaseConnectionManager;
import com.shsafe.common.struts.action.BaseAction;
import example.common.dto.PetDTO;
/**
* @author Michael J Chane
* @version $Revision: $ $Date: $
*/
public class PetAction extends BaseAction {
/**
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward search(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
PetForm petForm = ((PetForm) form);
DatabaseConnection connection = DatabaseConnectionManager.getMyConnection();
PetDAO dao = new PetDAO(connection);
int count = dao.countPets(petForm.getCondition());
petForm.getPageInfo().setMaxRecordNum(count);
if (count == 0) {
ActionMessages msgs = new ActionMessages();
msgs.add("all", new ActionMessage("dataNotFound"));
saveErrors(request, msgs);
return mapping.findForward("failure");
}
List<PetDTO> dtoList = dao.searchPets(petForm.getCondition(), petForm
.getPageInfo());
petForm.setListData(dtoList);
return mapping.findForward("success");
}
/**
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward update(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
PetForm petForm = ((PetForm) form);
DatabaseConnection connection = DatabaseConnectionManager.getMyConnection();
PetDAO dao = new PetDAO(connection);
int count = dao.updatePets(petForm.getListData());
log.info(count + " rows updated!");
ActionMessages msgs = new ActionMessages();
msgs.add("all", new ActionMessage("Success"));
saveMessages(request, msgs);
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -