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

📄 storehouseinfoaction.java

📁 一个关于tlms的一个小程序 看看能否帮助到别人
💻 JAVA
字号:
package com.szmx.tlms.admin.web;

import com.szmx.framework.base.web.BaseAction;
import com.szmx.framework.base.model.Pagination;
import com.szmx.tlms.admin.service.StorehouseInfoService;
import com.szmx.tlms.admin.model.StorehouseInfo;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2006-7-29
 * Time: 23:17:48
 * To change this template use File | Settings | File Templates.
 */
public class StorehouseInfoAction extends BaseAction {
    //查找数据
    public ActionForward searchStorehouseInfo(ActionMapping mapping,
                                              ActionForm form,
                                              HttpServletRequest request,
                                              HttpServletResponse response) throws Exception {
        //写日志
        if (log.isDebugEnabled()) {
            log.debug("Entering 'searchStorehouseInfo' method");
        }
        //得到页面中的Form对象
        DynaActionForm dynaForm = (DynaActionForm) form;
        //通过页面中的searchBean得到要查找的信息
        StorehouseInfo storehouseInfo = (StorehouseInfo) dynaForm.get("searchBean");
        //定义分页对象
        Pagination pagination = new Pagination(request, "pagination");
        //调用父类的方法得到service bean
        StorehouseInfoService mgr = (StorehouseInfoService) getBean("storehouseInfoService");
        //调用StorehouseInfo servuce层的方法返回一个分页对象
        pagination = mgr.searchStorehouseInfo(pagination, storehouseInfo);
        //将返回的分页对象保存到request中供页面使用
        request.setAttribute("pagination", pagination);
        return mapping.findForward("success");
    }

    //调用增加数据方法之前初始化
    public ActionForward initAddStorehouseInfo(ActionMapping mapping,
                                               ActionForm form,
                                               HttpServletRequest request,
                                               HttpServletResponse response) throws Exception {
        //写日志
        if (log.isDebugEnabled()) {
            log.debug("Entering 'searchStorehouseInfo' method");
        }
        //得到页面中的Form对象
        DynaActionForm dynaForm = (DynaActionForm) form;
        //实例化storehouseInfoBean
        StorehouseInfo storehouseInfoBean = new StorehouseInfo();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date newDate = new Date();
        //给storehouseInfoBean的 CreateDate属性赋默认值
        storehouseInfoBean.setCreateDate(format.format(newDate));
        dynaForm.set("storehouseInfoBean", storehouseInfoBean);
        //保存到request供页面调用
        request.setAttribute("storehouseInfoBean", storehouseInfoBean);
        return mapping.findForward("success");
    }

    //调用更新方法之前调用,初始化
    public ActionForward initEditStorehouseInfo(ActionMapping mapping,
                                                ActionForm form,
                                                HttpServletRequest request,
                                                HttpServletResponse response) throws Exception {
        //得到页面中的Form对象
        DynaActionForm dynaForm = (DynaActionForm) form;
        //调用父类的方法得到service bean
        StorehouseInfoService service = (StorehouseInfoService) getBean("storehouseInfoService");
        //得到页面Form对象中的属性storehouseInfoBean
        StorehouseInfo storehouseInfoBean = (StorehouseInfo) dynaForm.get("storehouseInfoBean");
        //根据页面中的storehouseInfoBean的id得到要编辑的对象
        StorehouseInfo resultBean = service.getStorehouseInfo(storehouseInfoBean.getId());
        //将要编辑的对象保存到form中
        dynaForm.set("storehouseInfoBean", resultBean);
        //将要编辑的对象保存到request中
        request.setAttribute("storehouseInfoBean", resultBean);
        return mapping.findForward("success");
    }

    //更新数据
    public ActionForward updateStorehouseInfo(ActionMapping mapping,
                                              ActionForm form,
                                              HttpServletRequest request,
                                              HttpServletResponse response) throws Exception {
        //得到页面中的Form对象
        DynaActionForm dynaForm = (DynaActionForm) form;
        //得到页面Form对象中的属性storehouseInfoBean
        StorehouseInfo storehouseInfoBean = (StorehouseInfo) dynaForm.get("storehouseInfoBean");
        //调用父类的方法得到service bean
        StorehouseInfoService service = (StorehouseInfoService) getBean("storehouseInfoService");
        //调用service层的 updateStorehouseInfo()方法更新数据
        service.updateStorehouseInfo(storehouseInfoBean);
        return mapping.findForward("success");
    }

    //删除数据
    public ActionForward deleteStorehouseInfo(ActionMapping mapping,
                                              ActionForm form,
                                              HttpServletRequest request,
                                              HttpServletResponse response) throws Exception {
        //写日志
        if (log.isDebugEnabled()) {
            log.debug("Entering 'delete' method");
        }
        //得到页面中的Form对象
        DynaActionForm dynaForm = (DynaActionForm) form;
        //得到页面中得idArr数组,得到选中的多条记录的id
        String[] splitString = (String[]) dynaForm.get("idArr");
        //调用父类的方法得到service bean
        StorehouseInfoService service = (StorehouseInfoService) getBean("storehouseInfoService");
        // 调用service层的 removeStorehouseInfo()方法删除数据
        service.removeStorehouseInfo(splitString);
        saveActionTripMessage(request, "message.delete");
        return mapping.findForward("success");
    }

    //增加数据
    public ActionForward addStorehouseInfo(ActionMapping mapping,
                                           ActionForm form,
                                           HttpServletRequest request,
                                           HttpServletResponse response) throws Exception {
        //写日志
        if (log.isDebugEnabled()) {
            log.debug("Entering 'addStorehouseInfo' method");
        }
        //调用父类的方法得到service bean
        StorehouseInfoService service = (StorehouseInfoService) getBean("storehouseInfoService");
        //得到页面中的Form对象
        DynaActionForm dynaForm = (DynaActionForm) form;
        //得到页面Form对象中的属性storehouseInfoBean
        StorehouseInfo storehouseInfo = (StorehouseInfo) dynaForm.get("storehouseInfoBean");
        //调用 StorehouseInfoService 。saveStorehouseInfo()保存数据
        service.saveStorehouseInfo(storehouseInfo);
        saveActionTripMessage(request, "message.add");
        return mapping.findForward("success");
    }

}

⌨️ 快捷键说明

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