📄 jfdaction.java
字号:
package org.HumResManSys.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 org.HumResManSys.actionForm.JfdForm;
import org.HumResManSys.factory.ServiceFactory;
import org.HumResManSys.vo.Jfd;
public class JfdAction extends DispatchAction {
private ServiceFactory serviceFactory;
Log log=LogFactory.getLog(JfdAction.class);
public ActionForward displayAllJfd(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
try {
// 获得页面提交的参数
String page=request.getParameter("pageNum");
//页面显示的初始当前页数
int pageNum=1;
if(page!=null){
//如果不是第一次打开,是点击了下一页,于是得把显示页面改为加一页
pageNum=Integer.valueOf(page)+1;
}
//把当前显示的第几页传给页面
request.setAttribute("pageNum", String.valueOf(pageNum));
pageNum=(pageNum-1)*10;
//查询所有信息,供分页显示用
// List listAll=serviceFactory.getEmployeeService().showAllEmployees();
int size=this.serviceFactory.getJfdService().getJfdsCount();
//查询一个页面的员工
List list=serviceFactory.getJfdService().queryJfdsByPage(pageNum, 10);
//告诉页面数据总数的大小
request.setAttribute("size", size);
//告诉页面一共有几页
request.setAttribute("num", String.valueOf((int)Math.ceil(size/10.0)));
/* System.out.println("分的页数是:"+(int)Math.ceil(listAll.size()/10.0));
System.out.println(listAll.size()/10);
System.out.println(Math.ceil(listAll.size()/10));
System.out.println(Math.ceil(0.1));*/
//把查询出来的一页的信息返回给页面
request.setAttribute("AllJfd", list);
return mapping.findForward("JFDadmin");
} catch (Exception e) {
e.printStackTrace();
log.debug("display AllJfd error");
request.setAttribute("error", "显示奖罚单信息失败!");
request.setAttribute("back2", "JfdAction.do?method=displayAllJfd");
return mapping.findForward("error");
}
}
public ActionForward saveOneJfd(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
try{
/*JfdForm jfdform=(JfdForm)form;*/
String emp_name=request.getParameter("emp_name");
String month=request.getParameter("month");
String jf_money=request.getParameter("jf_money");
String jf_name=request.getParameter("jf_name");
Jfd jfd=new Jfd();
//通过这个方法把form全部映射到vo的Jfd里边
//BeanUtils.copyProperties(jfd,jfdform);
jfd.setEmp_name(emp_name);
jfd.setJf_money(Long.parseLong(jf_money));
jfd.setMonth(month);
jfd.setJf_name(jf_name);
boolean okOrNot = serviceFactory.getJfdService().saveJfd(jfd);
if(okOrNot){
request.setAttribute("dest", "JfdAction.do?method=displayAllJfd");
return mapping.findForward("jump");
//return mapping.findForward("JFDadminDetailSuccess");
}else{
request.setAttribute("okOrNot", okOrNot);
request.setAttribute("error", "保存奖罚单信息失败!");
request.setAttribute("back2", "JfdAction.do?method=displayAllJfd");
return mapping.findForward("error");
}
}catch(Exception e){
e.printStackTrace();
log.debug("save one jfd error");
request.setAttribute("error", "保存奖罚单信息失败!");
request.setAttribute("back2", "JfdAction.do?method=displayAllJfd");
return mapping.findForward("error");
}
}
public void setServiceFactory(ServiceFactory serviceFactory) {
this.serviceFactory = serviceFactory;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -