Struts+Spring+Hibernate真正入门级实例(三)

 

EditPeopleAction.java

/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 
*/

package  action;

import
 java.util.ArrayList;
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.springframework.web.struts.ActionSupport;

import
 service.StudentManagerImpl;
import
 domain.People;

/** 
 * MyEclipse Struts
 * Creation date: 01-17-2007
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 
*/

public class EditPeopleAction extends ActionSupport  {

    
public
 ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) 
{
       
        String id
=request.getParameter("id"
);
    
        StudentManagerImpl manager
=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager"
);
        People people
=(People)manager.getPeople(new
 Integer(id));
        
        request.setAttribute(
"id"
, id);
        request.setAttribute(
"name"
, people.getName());
        request.setAttribute(
"location"
, people.getLocation());
        
        
return mapping.findForward("success"
);
    }

}

EditPeopleActionDo.java
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 
*/

package  action;

import
 java.util.ArrayList;
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.springframework.web.struts.ActionSupport;

import
 service.StudentManagerImpl;
import
 domain.People;

/** 
 * MyEclipse Struts
 * Creation date: 01-17-2007
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 
*/

public class EditPeopleActionDo extends ActionSupport  {

    
public
 ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) 
{
       
        People people
=
(People)form;
        
        StudentManagerImpl manager
=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager"
);
        
        People sPeople
=(People)manager.getPeople(new
 Integer(people.getId()));
        sPeople.setName(people.getName());
        sPeople.setLocation(people.getLocation());
        
        manager.editPeople(sPeople);
        
       
        List studentList
=manager.listPeople(0,5,"from People"
);
        request.setAttribute(
"studentList"
, studentList);
        request.setAttribute(
"currentPage"1
);
        
return mapping.findForward("success"
);
    }

}

ListPeopleAction.java
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 
*/

package  action;

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.springframework.web.struts.ActionSupport;

import
 service.StudentManagerImpl;
import
 util.PageSupport;

/** 
 * MyEclipse Struts
 * Creation date: 01-17-2007
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 
*/

public class ListPeopleAction extends ActionSupport  {

    
public
 ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) 
{
       
        
        String page
=request.getParameter("page"
);

        
int firstRow=0
;
        
int lastRow=0
;
        
        StudentManagerImpl manager
=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager"
);
        
        PageSupport sPage
=new
 PageSupport(page);
        sPage.setPagetotal(manager.listPeople().size());
        firstRow
=
sPage.calcFirstPage();
        lastRow
=
sPage.calcLastPage();
        
        
        List studentList
=manager.listPeople(firstRow-1,lastRow,"from People"
);
     
        request.setAttribute(
"studentList"
, studentList);
        request.setAttribute(
"currentPage"
, sPage.getThispage());
        
return mapping.findForward("success"
);
    }

}

SavePeopleAction.java
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 
*/

package  action;

import
 java.util.ArrayList;
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.springframework.web.struts.ActionSupport;

import
 service.StudentManagerImpl;
import
 domain.People;

/** 
 * MyEclipse Struts
 * Creation date: 01-17-2007
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 
*/

public class SavePeopleAction extends ActionSupport  {

    
public
 ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) 
{
       
        People people
=
(People)form;
    
        StudentManagerImpl manager
=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager"
);
        manager.savePeople(people);
        
        
        
return mapping.findForward("success"
);
    }

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值