Struts2自定义方法最佳实践

Terwer Struts2评论138字数 450阅读1分30秒阅读模式

自定义方法实现

在 struts.xml 配置 method ,并且在对应的 Action 实现对应方法即可。文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

struts.xml文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

<action name="login2" class="space.terwer.struts23.LoginAction2" method="myExecute">
    <result name="success">/result2.jsp</result>
</action>

Action文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

public String myExecute() throws Exception {
    System.out.println("myExecute called");
    return SUCCESS;
}

效果文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

Struts2自定义方法最佳实践文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

自定义方法的缺点

参数耦合,逻辑混乱。文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

自定义方法的优点

一个 Action 可以处理多种不同的逻辑文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

最佳实现

Struts2 支持自定义方法,即在 struts.xml 的 Action 元素内定义 method 属性,属性值即为待执行的方法。其中,该方法的声明要与 execute 保持一致。 (不推荐)这种方式容易导致 Action 方法混乱。文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

文章源自浅海拾贝-https://blog.terwergreen.com/struts2-custom-method-best-practice-1ap3gz.html

相关文章
  • 扫码加我微信
  • 验证消息请输入:来自你的博客
  • weinxin
  • 我的微信公众号
  • 微信扫一扫与我交流吧
  • weinxin
Terwer
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: