gpt4 book ai didi

struts2 - Struts 2.2.3 基于注释的验证

转载 作者:行者123 更新时间:2023-12-02 16:18:40 27 4
gpt4 key购买 nike

我在网络应用程序中使用struts 2.2.3。我想对从 UI 提交的表单数据使用基于 struts2 注释的验证。场景是:用户填写所有表单字段并单击提交按钮。我创建了一个 Person 类来存储注册表数据和 RegistrationAction 来触发注册逻辑。 RegistrationAction 持有对具有受人尊敬的 getter/setter 的 person 对象的引用。请建议如何在表单提交后使用 struts 2 注释验证 Person 类的各个字段。

谢谢。

最佳答案

尝试使用 Validations 注释的 fieldName 属性来实现它。类似于以下内容:

@Validations(
必填字段 =
{@RequiredFieldValidator(type = ValidatorType.SIMPLE, fieldName = "person.name", message = "您必须输入值名称。")}
)

请参阅以下链接以获取更多引用:

Struts2 Validation-annotation

关于struts2 - Struts 2.2.3 基于注释的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8813745/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com