天天看點

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)選擇第一個類進行繼承:

Action類

 實作了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;
}      
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;      

每個人都會有一段異常艱難的時光 。

生活的壓力 , 工作的失意 , 學業的壓力。

愛的惶惶不可終日。

挺過來的 ,人生就會豁然開朗。

挺不過來的 ,時間也會教你 ,怎麼與它們握手言和 ,是以不必害怕的。

——楊绛