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;
}