簡體   English   中英

如何對兩種操作方法使用相同的驗證方法

[英]How to use same validation method for two action methods

我在 Struts2 中有此方法的操作方法和驗證方法。 我想將此驗證方法用於另一種操作方法。 我不知道該怎么做。 請幫忙。 該場景描述如下:

public class ApplicantRegistrationDetails extends ActionSupport {
    
     public String personOfCollectiveTrademark() {
      // some code..
         
     }

     public String insertAndValidateIECcode(){
        // I have to use same validation method
        // for this method as above.

     }

     //validation
     public void validatePersonOfCollectiveTrademark() {
       // validations for first method
     }

}

您可以通過使用基於前綴的方法驗證輕松完成。

 /**
  * Validates insertAndValidateIECcode()
  */
 public void  validateInsertAndValidateIECcode(){
    // The implementation uses same validation method
    // for personOfCollectiveTrademark().
    validatePersonOfCollectiveTrademark();
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM