zoukankan      html  css  js  c++  java
  • Action类

    Action类的书写方式:

    1、方式一:POJO方式(不用继承任何父类,也不用实现任何接口):

    优点:使得Struts2框架的代码侵入性更低。

    public class HelloAction {//一个action中有多个方法
        public String add(){
            System.out.println("添加");
            return "success";
        }
    
        public String delete(){
            System.out.println("删除");
            return "success";
        }
    
        public String update(){
            System.out.println("修改");
            return "success";
        }
    
        public String selete(){
            System.out.println("查询");
            return "success";
        }
    }

    2、方式二:实现Action接口:

    (1)选择第一个类进行继承:

     实现了execute(),提供了Action的方法规范。

    import com.opensymphony.xwork2.Action;
    
    public class HelloAction implements Action {
        @Override
        public String execute() throws Exception {
            return null;
        }
    
    }

    (2)Action接口提供了一些字符串,可以在返回结果时使用:

    public interface Action {
        String SUCCESS = "success";
        String NONE = "none";
        String ERROR = "error";
        String INPUT = "input";
        String LOGIN = "login";
    
        String execute() throws Exception;
    }

    3、方式三:继承ActionSupport类:

    查看ActionSupport类的源码可知,ActionSupport实现了一系列接口:

    public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable {
        protected static Logger LOG = LoggerFactory.getLogger(ActionSupport.class);
        private final ValidationAwareSupport validationAware = new ValidationAwareSupport();
        private transient TextProvider textProvider;
        private Container container;
  • 相关阅读:
    配置navigation bar外观
    加急审核
    UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用
    打开某个好友的聊天界面
    ALAssets的两种用法
    更改appstore开发商名字
    回调函数的使用
    相应字体所占的位置大小
    IOS的变量前加extern和static字段
    iOS开发代码规范(通用)
  • 原文地址:https://www.cnblogs.com/zhai1997/p/12206616.html
Copyright © 2011-2022 走看看