Struts+Spring+Hibernate整合的简单实例(6)
发布时间:2021-06-05
发布时间:2021-06-05
Struts+Spring+Hibernate整合的简单实例
[java]viewplaincopy
packagecom.sshexample.web.action;
importjava.util.List;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importorg.apache.struts.action.ActionForm;
importorg.apache.struts.action.ActionForward;
importorg.apache.struts.action.ActionMapping;
importorg.apache.struts.action.DynaActionForm;
importorg.apache.struts.actions.DispatchAction;
importcom.sshexample.model.Test;
importcom.sshexample.service.TestManager;
publicclassTestActionextendsDispatchAction{
//testManager对象
privateTestManagertestManager;
//注入口
publicvoidsetTesetManager(TestManagertesetManager){
this.testManager=tesetManager;
}
//编辑方法
publicActionForwardedit(ActionMappingmapping,ActionFormform, HttpServletRequestrequest,HttpServletResponseresponse){
//动态ActionForm实例化
DynaActionFormtestForm=(DynaActionForm)form;
//参数
Stringid=request.getParameter("id");
//获得test对象
Testt=testManager.getTest(id);
//设值
testForm.set("name",t.getName());
//存储ID到request
request.setAttribute("id",id);
returnmapping.findForward("edit");
}
//更新数据
publicActionForwardsave(ActionMappingmapping,ActionFormform, HttpServletRequestrequest,HttpServletResponseresponse){
//动态ActionForm实例化
DynaActionFormtestForm=(DynaActionForm)form;
//参数
上一篇:色彩对环境和心理的影响