• 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;
  • 相关阅读:
    jQuery检测滚动条(scroll)是否到达底部
    sql group by
    hbm.xml 详解总结
    net.sf.json 时间格式的转化
    经典SQL语句大全
    HashTable
    in与exist , not in与not exist 的区别
    网页布局常用的一些命名规则和书写
    什么是SOA?
    sql之left join、right join、inner join的区别
  • 原文地址:https://www.cnblogs.com/zhai1997/p/12206616.html
Copyright © 2020-2023  润新知