• struts2的action方法执行顺序 Preparable


    需要实现 com.opensymphony.xwork2.Preparable接口,继承ActionSupport类:

    public class OrderActionMethod extends ActionSupport implements Preparable {

    private String username;

    @Override
    public void prepare() throws Exception {
    System.out.println(" method prepare start ... ");
    }
    @Override
    public String execute() throws Exception {
    System.out.println(" method execute start ... ");
    return SUCCESS;
    }
    @Override
    public void validate() {
    System.out.println(" method validate start ... ");
    }


    public String prepareAddUser(){
    System.out.println(" method prepareaAddUser start ... ");
    return SUCCESS;
    }

    public String validateAddUser(){
    System.out.println(" method validateAddUser start ... ");
    return SUCCESS;
    }

    public String addUser(){
    System.out.println(" method addUser start ... ");
    return SUCCESS;
    }


    public String getUsername() {
    System.out.println(" method getUsername start ... ");
    return username;
    }

    public void setUsername(String username) {
    System.out.println(" method setUsername start ... ");
    this.username = username;
    }
    }

      1、按照上面的执行addUser顺序为:

        10:21:30,695 INFO [STDOUT] method prepareaAddUser start ... 
        10:21:30,695 INFO [STDOUT] method prepare start ... 
        10:21:30,695 INFO [STDOUT] method setUsername start ... 
        10:21:30,696 INFO [STDOUT] method validateAddUser start ... 
        10:21:30,696 INFO [STDOUT] method validate start ... 
        10:21:30,696 INFO [STDOUT] method addUser start ... 

        从结果可以 prepare方法名方法  --> prepare方法 -->set方法--> validate方法名方法 -->validate方法--> 方法;   

      2、请求执行execute默认方法或执行 localhost:8080//manage/orderActionMethod.action?username=s(也就是没有指定要执行的方法):

        10:59:52,706 INFO [STDOUT] method prepare start ...
        10:59:52,706 INFO [STDOUT] method setUsername start ...
        10:59:52,706 INFO [STDOUT] method validate start ...
        10:59:52,706 INFO [STDOUT] method execute start ...

  • 相关阅读:
    批量创建账号脚本
    shell 批量创建_备份 mysql 数据库 表
    优化chkconfig
    cut 命令
    Shell for 循环
    while 读取文件内容
    生成随机数
    linux 资源管理
    shell 脚本后台运行知识
    while 语句
  • 原文地址:https://www.cnblogs.com/lbangel/p/3094474.html
Copyright © 2020-2023  润新知