/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.zouzhicai.struts.action;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.dozer.util.mapping.MapperIF;
import net.sf.dozer.util.mapping.MappingException;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.actions.DispatchAction;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.struts.DispatchActionSupport;
import com.zouzhicai.model.manager.IUserinfoManager;
import com.zouzhicai.model.pojo.Userinfo;
import com.zouzhicai.struts.form.UserForm;
/**
* MyEclipse Struts
* Creation date: 06-17-2007
*
* XDoclet definition:
* @struts.action path="/user" name="userForm" input="/useredit.jsp" parameter="method" scope="request" validate="true"
*/
//继承 父类 DispatchActionSupport
public class UserAction extends DispatchActionSupport {
private IUserinfoManager ium;
private MapperIF mif;
//实现setServlet()方法
@Override
public void setServlet(ActionServlet arg0) {
super.setServlet(arg0);
WebApplicationContext wac = super.getWebApplicationContext();
ium = (IUserinfoManager)wac.getBean("usermanager");
mif = (MapperIF)wac.getBean("mif");
System.out.println(mif);
}
@Override
protected ActionForward unspecified(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
return list(arg0, arg1, arg2, arg3);
}
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List listvo = ium.getfindUserinfo();
request.setAttribute("listvo",listvo);
return mapping.findForward("list");
}
public ActionForward showadd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.setAttribute("action","saveadd");
return mapping.getInputForward();
}
public ActionForward saveadd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm userform = (UserForm)form;
Userinfo userinfo = new Userinfo();
try {
BeanUtils.copyProperties(userinfo,userform);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
//try {
//mif.map(userform,userinfo);
//} catch (MappingException e) {
//e.printStackTrace();
//System.out.println("拷贝数据出错...");
//}
ium.adduserinfo(userinfo);
return mapping.findForward("listaction");
}
public ActionForward showupdate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm userform = (UserForm)form;
//得到页面传递过来的id值
String id = request.getParameter("uuid");
//调用manager里边的查询单条记录的方法;
Userinfo userinfo = ium.getOneUserinfo(id);
try {
//实现数据的拷贝
BeanUtils.copyProperties(userform,userinfo);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
// try {
// mif.map(userinfo,userform);
// } catch (MappingException e) {
// System.out.println("实现数据拷贝时出错...");
// e.printStackTrace();
// }
request.setAttribute("action","saveupdate");
return mapping.getInputForward();
}
public ActionForward saveupdate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm userform = (UserForm)form;
Userinfo userinfo = new Userinfo();
try {
BeanUtils.copyProperties(userinfo,userform);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
ium.updateuserinfo(userinfo);
//这样也可以实现跳转,并且是重定向
//return new ActionForward("/user.do?method=listaction",true);
return mapping.findForward("listaction");
}
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String[] ids = request.getParameterValues("uuid");
ium.deleteuserinfo(ids);
return mapping.findForward("listaction");
}
}
评论0