在具有多个操作的类中具有多个验证功能 [英] Having multiple validation functions in a class with multiple actions

查看:21
本文介绍了在具有多个操作的类中具有多个验证功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Struts 2 中使用 action 类中的验证函数来验证表单.

I want to validate forms in Struts 2 using validate functions in the action class.

我找到了这个例子:http://www.javatpoint.com/struts-2-custom-validation-workflow-interceptor

但是,我想在同一个类中有多个功能(操作).我想对这些功能中的每一个都有一个验证功能.我们该怎么做?

However, I want to have multiple functions (actions) in the same class. And I want to have a validation function for each of these functions. How can we do this?

示例中的 validate() 函数会自动调用,因为它是 Validateable 接口函数之一.如果我有其他名称的验证函数,它们将不会被调用

The validate() function in the example gets invoked automatically since it is one of the Validateable interface functions. If I have validate functions with other names they won't be invoked

推荐答案

创建 validateXxx 方法,其中 Xxx 是相关操作方法的名称.

Create validateXxx methods where Xxx is the name of the related action method.

(这是否是最佳选择取决于您需要的特定验证.)

(Whether or not this is the best option depends on the particular validations you need.)

这篇关于在具有多个操作的类中具有多个验证功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆