struts-annotations-plugin 介绍

来源:互联网 发布:平安达电子狗升级软件 编辑:程序博客网 时间:2024/05/04 21:20

下载:http://code.google.com/p/struts-annotations-plugin/downloads/list

  1. Exposing an Action and an ActionForm
/**  * The path to this action will be "/searchBookAction" if no path  * it's specified.  */ @Action(form=BookForm.class) public class SearchBookAction extends Action { .... }  /**  * The name used by Struts to save this form into  * Request or Session will be "bookForm" if no name  * it's specified.  */ @Form public class BookForm extends Form { }
  • Exposing an Action with a forward
/**  * The path to this action will be "/searchBook". The "/" character  * it's optional.  * The @Forward annotation it's used to configure the action forward. If  * more forwards are needed, then use @Forwards annotation.  * If both annotations are present, the @Forward annotation has higher priority.  */ @Action(path="/searchBook", form=BookForm.class) @Forward(name="success", path="/pages/main.jsp") public class SearchBookAction extends Action { .... }
  • Exposing an Action with many forwards
/**  * The path to this action will be "/searchBook". The "/" character  * it's optional.  */ @Action(path="/searchBook", form=BookForm.class) @Forwards({         @Forward(name="success", path="/pages/main.jsp")         @Forward(name="error", path="/pages/error.jsp") }) public class SearchBookAction extends Action { .... }
  • A little more complex (?) example
@Action(path="/searchBook", form=BookForm.class) @Input("/pages/login.jsp") @Forwards({         @Forward(name="success", path="/pages/main.jsp")         @Forward(name="error", path="/pages/error.jsp") }) @SetProperties({         @Property(property="checkLogin" value="true"),         @Property(property="checkRoles" value="true") }) @Validate public class SearchBookAction extends Action { .... }
  • What about a DispatchAction....?
/**  * The @Dispatch annotation tells the name of the parameter to be used  * to identify the method to be invoked by Struts. The @Parameter also  * works. The @Dispath annotation exists only for making the code more readable.  */ @Action(form=BookForm.class) @Dispatch("action") @Input("/pages/bookList.jsp") @Forward(name="success", path="/pages/main.jsp") public class CheckBookAction extends DispatchAction { ... }
  • I have a lot of dynamic forms....
/**  * By just annotating a form bean with @Form and @FormProperties  * annotations, the form bean it's processed as a dynamic form.  * Note that the real power of dynamic forms it's losted here.   * Configuration directly on struts-config.xml it's highly recomended for this cases.  */ @Form @FormProperties({             @FormProperty(name="name", type=String.class),             @FormProperty(name="age", type=Integer.class),             @FormProperty(name="adress", type=String.class) }) public class MyBaseDynaForm extends DynaActionForm { ... }
另一个实现:http://code.google.com/p/struts-annotations/
原创粉丝点击