baseaction.java

来自「本程序实现了一个访问控制系统」· Java 代码 · 共 37 行

JAVA
37
字号
package org.appfuse.webapp.action;

import org.apache.struts.actions.DispatchAction;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.apache.commons.logging.*;

/**
 * Base Action class for the whole application. New Action should
 * extend this class or the specific sub-class.
 */

public class BaseAction
    extends DispatchAction {
    /** Spring Application context */
    private static ApplicationContext ctx = null;
    private static Log log = LogFactory.getLog(BaseAction.class);
    public void copyProperties(Object to, Object from) throws Exception {
        BeanUtils.copyProperties(to, from);
    }

    /**
     * Convenience method to bind objects in Actions
     * @param name the bean name
     * @return Object bind to the name
     */
    public Object getBean(String name) {
        if (ctx == null) {
            ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(
                servlet.getServletContext());
        }
        return ctx.getBean(name);
    }

}

⌨️ 快捷键说明

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