abstract class BaseAction

  在struts2 in action中所见,这样封装后省去了大部分crud重复代码,虽然还不能理悟,先记下来。

  abstract class BaseAction extends ActionSupport {

  protected DB db;

  protected static Log log = LogFactory.getLog(BaseAction.class);

  private long requestId;

  private boolean readOnly = false;

  private String mappedRequest;

  @SkipValidation

  public String show(){

  setReadOnly(true);

  setMappedRequest(Constants.LIST);

  return SUCCESS;

  }

  @SkipValidation

  public String add(){

  setMappedRequest(Constants.SAVE);

  return SUCCESS;

  }

  public String save(){

  db.save(getModel());

  return list();

  }

  @SkipValidation

  public String edit(){

  setMappingRequest(Constants.UPDATE);

  return SUCCESS;

  }

  public String update(){

  db.save(getModel());

  return list();

  }

  @SkipValidation

  public String destroy(){

  setReadOnly(true);

  setMappingRequest(Constants.REMOVE);

  return Constants.SUCCESS;

  }

  public String remove(){

  db.remove(getModel());

  return list();

  }

  @SkipValidation

  public String list(){

  setMappingedRequest(Constants.LIST);

  return Constants.LIST;

  }

  public String getActionClass(){

  return getClass()。getSimpleName();

  }

  public String getDestination(){

  return getClass()。getSimpleName();

  }

  public String getActionMethod(){

  return mappedRequest;

  }

  public void setActionMethod(String method){

  this.mappedRequest = method;

  }

  public void setMappedRequest(String actionMethed){

  this.mappedRequest = getActionClass() + "_" + actionMethed;

  log.debug("setting mappedRequest to "+ getActionClass() + "_" + actionMethed);

  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值