0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Conventionプラグインを使ったActionクラスの書き方

Posted at

Conventionプラグインを使ったActionクラスの書き方

Conventionプラグインを使うとActionクラスの定義はアノテーションで一括定義できます。
具体的には次のようになります。

@Namespace("/")
@ParentPackage("json-default")
@InterceptorRefs({
    @InterceptorRef("jsonValidationWorkflowStack")
})
@Results({
    @Result(name = ActionSupport.SUCCESS,type = "dispatcher",location = "index.jsp"),
})
@ExceptionMappings({
    @ExceptionMapping(exception="java.lang.Exception" , result="exception")
})
public class SampleAction extends ActionSupport {
    @Action("")	
    public String sample() throws Exception {
        return SUCCESS;
    }
}

他にもアノテーションで定義できるものはありますが、一般的にはここに挙げているものだけで問題ありません。
なお、Validation定義はConventionプラグインには含まれていません。

ちなみに、さらにSpringプラグインとlombokを使って記載するとさらにアノテーションだらけになりますが、設定する内容は決まりきっていることが多いのでテンプレート化しやすいでしょう。

@Namespace("/")
@ParentPackage("json-default")
@InterceptorRefs({
    @InterceptorRef("jsonValidationWorkflowStack")
})
@Results({
    @Result(name = ActionSupport.SUCCESS,type = "dispatcher",location = "index.jsp"),
})
@ExceptionMappings({
	@ExceptionMapping(exception="java.lang.Exception" , result="exception")
})
@Controller
@Scope("prototype")
public class SampleAction extends ActionSupport {
	@Action("")
	public String sample() throws Exception {
		return SUCCESS;
	}
	
	@Getter @Setter
	private String value;
	
	@Autowired
	private ValidatorService service;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?