📄 addguestmanageaction.java
字号:
/**
*
*/
package cn.bway.foreigntrade.operation.guestmanage.action;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.http.*;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.*;
import org.hibernate.Session;
import org.hibernate.Transaction;
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;
import cn.bway.foreigntrade.operation.guestmanage.form.GuestmanageForm;
import cn.bway.foreigntrade.operation.guestmanage.model.Guestmanage;
import cn.bway.foreigntrade.operation.providemanagement.impl.ProvidemanaManagerFactory;
/**
* @author Kson
*
*/
public class AddGuestmanageAction 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 {
GuestmanageForm pForm = (GuestmanageForm) form;
ActionErrors errors = new ActionErrors();
String returnStr = WebConstant.FORWARD_SUCCESS;
Session sess=null;
Transaction tx=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();
saveObject(pForm,sess);
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);
tx.rollback();
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return mapping.findForward(returnStr);
}
/**
* 构建VO,保存对象�������?
* @throws BwayHibernateException
* @throws BwayException
*/
private void saveObject(GuestmanageForm form,Session sess
) throws BwayHibernateException, BwayException{
Guestmanage guest=new Guestmanage();
try{
guest.setCountry(form.getCountry());
guest.setNames(form.getNames());
guest.setPropertys(form.getPropertys());
guest.setDeliver(form.getDeliver());
guest.setAddress(form.getAddress());
guest.setSupply(form.getSupply());
guest.setReview(form.getReview());
guest.setContractcode(form.getContractcode());
guest.setCharter(form.getCharter());
guest.setPayment(form.getPayment());
guest.setAppointment(form.getAppointment());
guest.setExpress(form.getExpress());
guest.setContractleave(form.getContractleave());
// BeanUtils.copyProperties(guest, form);
sess.save(guest);
}catch(Exception e){
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -