📄 addstaffinfoaction.java
字号:
/**
*
*/
package cn.bway.admin.staff.action;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.bway.admin.staff.form.StaffinfoForm;
import cn.bway.admin.staff.impl.StaffinfoManagerFactory;
import cn.bway.admin.staff.model.Staffinfo;
import cn.bway.common.BwayException;
import cn.bway.common.BwayHibernateException;
import cn.bway.common.Util;
import cn.bway.common.WebConstant;
import cn.bway.common.action.BaseAction;
import cn.bway.common.dao.HibernateSessionFactory;
/**
* @author Kson
*
*/
public class AddStaffinfoAction extends BaseAction {
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws BwayException
* @throws SQLException
* @throws Exception
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,HttpServletRequest request, HttpServletResponse response)
throws BwayHibernateException, BwayException, SQLException {
StaffinfoForm pForm = (StaffinfoForm) form;
ActionErrors errors = new ActionErrors();
String returnStr = WebConstant.FORWARD_SUCCESS;
Session sess=null;
Transaction tx=null;
Connection conn=null;
//处理get请求����get����
if(request.getMethod().equals("GET")){
request.setAttribute(WebConstant.PAGE_Object, pForm);
returnStr = WebConstant.FORWARD_INITPAGE;
return mapping.findForward(returnStr);
}
try {
sess=HibernateSessionFactory.currentSession();
// tx=sess.beginTransaction();
conn=sess.connection();
conn.setAutoCommit(false);
String tmpTableId = Util.getTableValueId("staffinfo",conn);
saveObject(pForm,sess,tmpTableId);
conn.commit();
// tx.commit();
returnStr=WebConstant.FORWARD_SUCCESS;
request.setAttribute(WebConstant.RETURN_Message,"添加成功!");
} catch (BwayHibernateException e) {
returnStr=WebConstant.FORWARD_FAIL;
errors.add(ActionErrors.GLOBAL_ERROR,new ActionError("edu.system.excption",e.getMessage()));
this.saveErrors(request,errors);
conn.rollback();
tx.rollback();
e.printStackTrace();
}finally{
if(null !=conn){
conn.close();
}
HibernateSessionFactory.closeSession();
}
return mapping.findForward(returnStr);
}
/**
* 构建VO,保存对象�������
* @throws BwayHibernateException
* @throws BwayException
*/
private void saveObject(StaffinfoForm form,Session sess,
String tmpTableId) throws BwayHibernateException, BwayException{
//得到父类型对象�õ������Ͷ���
Staffinfo pvo=new Staffinfo();
try{
pvo.setMenuid(form.getMenuid());
pvo.setMenufatherid(form.getMenufatherid());
pvo.setStaffid(tmpTableId);
pvo.setStaffname(form.getStaffname());
pvo.setPassward(form.getPassward());
pvo.setPhone(form.getPhone());
pvo.setMobile(form.getMobile());
pvo.setSex(form.getSex());
pvo.setEmail(form.getEmail());
pvo.setStaffcnname(form.getStaffcnname());
pvo.setDeptid(form.getDeptid());
pvo.setDeptname(form.getDeptname());
pvo.setNoid(form.getNoid());
pvo.setAge(form.getAge());
pvo.setBirthday(form.getBirthday());
pvo.setIdentitys(form.getIdentitys());
pvo.setNationals(form.getNationals());
pvo.setOrigin(form.getOrigin());
pvo.setAccountlocation(form.getAccountlocation());
pvo.setIsmarriage(form.getIsmarriage());
pvo.setQualifications(form.getQualifications());
pvo.setProfessional(form.getProfessional());
pvo.setGraduate(form.getGraduate());
pvo.setStartjobtime(form.getStartjobtime());
pvo.setEndjobtime(form.getEndjobtime());
pvo.setJobinunit(form.getJobinunit());
pvo.setEndjobinunit(form.getEndjobinunit());
pvo.setDuty(form.getDuty());
pvo.setTitles(form.getTitles());
pvo.setPolitical(form.getPolitical());
pvo.setHomeaddr(form.getHomeaddr());
pvo.setJobchanges(form.getJobchanges());
pvo.setTeachback(form.getTeachback());
pvo.setJobdetail(form.getJobdetail());
pvo.setAwardrecords(form.getAwardrecords());
pvo.setSocial(form.getSocial());
pvo.setMedicalrecord(form.getMedicalrecord());
pvo.setDetail(form.getDetail());
pvo.setAddtime(Util.fotmatDate3(new java.util.Date()));
sess.save(pvo);
// StaffinfoManagerFactory.getStaffinfoManager().addStaffinfo(pvo);
}catch(Exception e){
e.printStackTrace();
// throw new BwayException (e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -