📄 reseacheraction.java
字号:
package com.wiely.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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.wiely.commons.Pager;
import com.wiely.service.IReseacherService;
import com.wiely.struts.form.ReseacherForm;
import com.wiely.vo.Reseacher;
public class ReseacherAction extends DispatchAction {
private int currentPage = 1;
/*
* Spring inject
*/
private IReseacherService reseacherService;
public IReseacherService getReseacherService() {
return reseacherService;
}
public void setReseacherService(IReseacherService reseacherService) {
this.reseacherService = reseacherService;
}
/**
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
@SuppressWarnings("unchecked")
public ActionForward browerReseachers(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ReseacherForm rf = (ReseacherForm) form;
int totalSize = reseacherService.getTotalSize();
currentPage = rf.getCurrentPage();
System.out.println("^^^^^^^^^^^^^^currentPage:" + rf.getCurrentPage());
Pager pager = new Pager(currentPage, totalSize);
List reseachers = reseacherService.getReseacher(currentPage, pager
.getPageSize());
HttpSession session = request.getSession();
session.setAttribute("reseachers", reseachers);
request.setAttribute("pager", pager);
return mapping.findForward("reseacher");
}
public ActionForward insertReseacher(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ReseacherForm rf=(ReseacherForm)form;
String name=rf.getName();
String sex=rf.getSex();
String career=rf.getCareer();
String title=rf.getTitle();
Reseacher reseacher=new Reseacher();
reseacher.setCareer(career);
reseacher.setName(name);
reseacher.setTitle(title);
reseacher.setSex(sex);
reseacherService.saveResearcher(reseacher);
return mapping.findForward("update");
}
public ActionForward updateReseacher(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ReseacherForm rf=(ReseacherForm)form;
String name=rf.getName();
String sex=rf.getSex();
String career=rf.getCareer();
String title=rf.getTitle();
int rid=Integer.parseInt(rf.getR());
Reseacher reseacher=new Reseacher();
reseacher.setCareer(career);
System.out.println("$$$$$$$$$$$$$$Rid:"+rid);
System.out.println("$$$$$$$$$$$$$$Career:"+career);
reseacher.setRid(rid);
reseacher.setName(name);
reseacher.setTitle(title);
reseacher.setSex(sex);
reseacherService.updateReseacher(reseacher);
return mapping.findForward("update");
}
public ActionForward deleteReseacher(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ReseacherForm rf=(ReseacherForm)form;
int rid=rf.getCheck();
reseacherService.delReseacher(rid);
return mapping.findForward("update");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -