Struts 2注記構成の@Resultsと@Result

2699 ワード

Struts 2注記構成の@Action(二)では結果ページに対してConvention Pluginの約束を採用していますが、@Resultsと@Resultでこの約束を変更する必要があります.クラスとメソッドを@Resultsと@Resultで注釈した結果の効果もあります.
コード:
package com.example.actions;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

@Results( { @Result(name = "global", location = "/global.jsp") })
public class HelloWorld5 extends ActionSupport {

	@Action(value = "/H5/url", results = { @Result(name = SUCCESS, location = "/H5/success.jsp"),
			@Result(name = "failure", location = "/H5/fail.jsp") })
	public String execute() {
		if (System.currentTimeMillis() % 3 == 0) {
			return "failure";
		} else if (System.currentTimeMillis() % 3 == 1) {
			return SUCCESS;
		} else {
			return "global";
		}
	}

	@Action("globalTest")
	public String global() {
		return "global";
	}

	@Action(value = "globalOverWrite", results = { @Result(name = "global", location = "/H5/globalOverWrite.jsp") })
	public String globalOverWrite() {
		return "global";
	}

}
      @Result    Convention Plugin       。 

    String execute()          @Action(value = "/H5/url", results = { @Result(name = SUCCESS, location = "/H5/success.jsp"),
            @Result(name = "failure", location = "/H5/fail.jsp") })  。  @Action(...)  results = { @Result(name = SUCCESS, location = "/H5/success.jsp"),
            @Result(name = "failure", location = "/H5/fail.jsp") },    Convention Plugin   ,      /H5/url.jsp。          ,execute()     ,          ,           。

     Action   @Result  ,@Result  Action          。

        , HelloWorld5    @Results( { @Result(name = "global", location = "/global.jsp") })  。                         “global”     。      "/global.jsp"。              "/global.jsp"      @Result(name = "global", location = "/global.jsp")  。                  。       execute()   global()  。           “global”     ( location     “/global.jsp”  )。

     Action       @Result  ,@Result           。Action       @Result     Action     @Result。(      )

          globalOverWrite()  ,          “global”   。          @Action(value = "globalOverWrite", results = { @Result(name = "global", location = "/H5/globalOverWrite.jsp") })  。    @Result(...)          “global”       。  ,             /H5/globalOverWrite.jsp               “/global.jsp”  。