⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addsmalltagaction.java

📁 这是本人曾经在公司里用的,内部开发框架,基于struts+hibernate今天分享给大家
💻 JAVA
字号:
/**
 * 
 */
package cn.bway.foreigntrade.commondata.smalltag.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.commondata.smalltag.form.SmalltagForm;
import cn.bway.foreigntrade.commondata.smalltag.model.Smalltag;



/**
 * @author Kson
 *
 */
public class AddSmalltagAction 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 {
		
		SmalltagForm pForm = (SmalltagForm) 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(SmalltagForm form,Session sess
			) throws BwayHibernateException, BwayException{
        
		Smalltag guest=new Smalltag();
		try{
			
			guest.setColor(form.getColor());					
			guest.setSizes(form.getSizes());
			guest.setQty(form.getQty());	
			
			sess.save(guest);
			

		}catch(Exception e){
			e.printStackTrace();
		
		}
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -