📄 studentaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.team.struts.action;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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.actions.DispatchAction;
import com.team.base.Dao;
import com.team.pojo.Student;
import com.team.struts.form.StudentForm;
/**
* MyEclipse Struts
* Creation date: 07-29-2008
*
* XDoclet definition:
* @struts.action path="/student" name="studentForm" parameter="method" scope="request" validate="true"
*/
public class StudentAction extends DispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward enter(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
StudentForm studentForm = (StudentForm) form;// TODO Auto-generated method stub
HttpSession session = request.getSession();
Dao dao = new Dao();
List team_list;
team_list=dao.excetueQuery("from Team");
session.setAttribute("teamList", team_list);
return mapping.findForward("enterStu");
}
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
StudentForm studentForm = (StudentForm) form;// TODO Auto-generated method stub
try {
Student student = new Student();
BeanUtils.copyProperties(student, studentForm);
Dao dao = new Dao();
dao.save(student);
return mapping.findForward("Suceess");
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("addFail");
}
public ActionForward enterManager(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Dao dao = new Dao();
List team_list;
List stu_list;
team_list=dao.excetueQuery("from Team");
stu_list=dao.excetueQuery("from Student");
request.setAttribute("teamList", team_list);
request.setAttribute("stuList", stu_list);
return mapping.findForward("enterManagerStu");
}
public ActionForward change(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String temp=request.getParameter("teamType");
Integer teamType=Integer.valueOf(temp);
Dao dao = new Dao();
List team_list;
List stu_list;
team_list=dao.excetueQuery("from Team");
stu_list=dao.excetueQuery("from Student where teamType='"+teamType+"'");
request.setAttribute("temp",temp);
request.setAttribute("teamList", team_list);
request.setAttribute("stuList", stu_list);
return mapping.findForward("enterManagerStu");
}
/**
* 进入 修改学生页面
*/
public ActionForward enterModify(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String temp=request.getParameter("stuId");
Integer stuId=Integer.valueOf(temp);
Dao dao = new Dao();
List team_list;
List stu_list;
team_list=dao.excetueQuery("from Team");
stu_list=dao.excetueQuery("from Student where stuId='"+stuId+"'");
request.setAttribute("teamList", team_list);
request.setAttribute("stuList", stu_list);
return mapping.findForward("enterModify");
}
/**
* 修改学生信息
*/
public ActionForward modify(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
StudentForm studentForm = (StudentForm) form;// TODO Auto-generated method stub
try {
Student student = new Student();
BeanUtils.copyProperties(student, studentForm);
Dao dao = new Dao();
dao.update(student);
return mapping.findForward("modifySuceess");
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("modifyFail");
}
/**
* 删除学生
*
*/
public ActionForward del(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String temp=request.getParameter("stuId");
Integer stuId=Integer.valueOf(temp);
Dao dao = new Dao();
if(dao.remove("delete Student where stuId='"+stuId+"'")){
return mapping.findForward("delSuceess");
}
return mapping.findForward("delFail");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -