分享

JFinal validator一个校验类对应多个验证的方法

 hongjing_z 2017-10-12

需求场景:
一个表单提交过程中对应多个验证方法,为了不建立多个validatorXXX.class,如何将每个方法前的校验类具体到方法?

解决办法:

public class ControllerXXX extends Controller {
@Before(ValidatorXXX.class)
public method1(){}

@Before(ValidatorXXX.class)
public method2(){}
}

public class ValidatorXXX extends Validator {

protected void validate(Controller controller) {
String methodName = getActionMethod().getName();
if (methodName.equals(“method1”)) {
//method1的验证
} else if (methodName.equals(“method2”)) {
//method2的验证
}

}

protected void handleError(Controller controller) {
String methodName = getActionMethod().getName();
if (methodName.equals(“method1”)) {
//method1的处理
} else if (methodName.equals(“method2”)) {
//method2的处理
}
}
}

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多