📄 friendfindbyprimarykeyaction.java
字号:
package com.relationinfo.txl.struts.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
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.txl.dao.FriendDao;
import com.relationinfo.txl.dto.Friend;
import com.relationinfo.txl.factory.FriendDaoFactory;
import com.relationinfo.txl.struts.forms.FriendForm;
public class FriendFindByPrimaryKeyAction 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 _xmjp = request.getParameter("xmjp");
//创建Dao类
FriendDao dao = FriendDaoFactory.create();
// 执行查询
Friend dto = dao.findByPrimaryKey(_xmjp);
// 检测是否查到记录
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
FriendForm friendForm = new FriendForm();
friendForm.setCrudMethod( request.getParameter("crudMethod") );
friendForm.setXmjp(dto.getXmjp());
friendForm.setGroupid(dto.getGroupid());
friendForm.setName(dto.getName());
friendForm.setAge(dto.getAge());
friendForm.setSex(dto.getSex());
friendForm.setProfessional(dto.getProfessional());
friendForm.setScholarship(dto.getScholarship());
friendForm.setAddress(dto.getAddress());
friendForm.setEmail(dto.getEmail());
friendForm.setPhone(dto.getPhone());
friendForm.setNote(dto.getNote());
// 存储结果
request.getSession().setAttribute( "Friend", friendForm );
return mapping.findForward( crudMethod );
}
catch (Exception e) {
ActionErrors _errors = new ActionErrors();
_errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("internal.error", e.getClass().getName() + ": " + e.getMessage() ) );
saveErrors( request, _errors );
return mapping.findForward( "failure" );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -