struts-annotations-plugin 介绍

下载: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/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值